diff --git a/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java b/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java --- a/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java +++ b/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java @@ -1868,9 +1868,18 @@ newAtomicDoc.addAtomicLockListener(listenerImpl); } + // #269262 when IME is used, deinstall and install method is invoked + // so in such case, the existing position shoud be used + // because newDoc.StartPosition() may be an incorrect position + CaretInfo lastCaret = getLastCaret(); + Position dotPos = lastCaret.getDotPosition(); + if (dotPos == null) { + dotPos = newDoc.getStartPosition(); + } + // Set caret to zero position upon document change (DefaultCaret impl does this too) runTransaction(CaretTransaction.RemoveType.REMOVE_ALL_CARETS, 0, - new CaretItem[] { new CaretItem(this, newDoc.getStartPosition(), Position.Bias.Forward, + new CaretItem[] { new CaretItem(this, dotPos, Position.Bias.Forward, null, Position.Bias.Forward ) }, null); // Leave caretPos and markPos null => offset==0 @@ -1902,6 +1911,11 @@ } finally { doc.readUnlock(); } + } else { + // #269262 avoid that update() is not invoked + synchronized (listenerList) { + caretUpdatePending = false; + } } } };