mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: unified - keep caret position on content update
This commit is contained in:
@@ -65,6 +65,14 @@ public class LineCol {
|
||||
}
|
||||
|
||||
public static int toOffset(@NotNull Document document, @NotNull LineCol linecol) {
|
||||
return document.getLineStartOffset(linecol.line) + linecol.column;
|
||||
return linecol.toOffset(document);
|
||||
}
|
||||
|
||||
public static int toOffset(@NotNull Document document, int line, int col) {
|
||||
return new LineCol(line, col).toOffset(document);
|
||||
}
|
||||
|
||||
public int toOffset(@NotNull Document document) {
|
||||
return document.getLineStartOffset(line) + column;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +384,13 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase {
|
||||
public void run() {
|
||||
myFoldingModel.updateContext(myRequest, getFoldingModelSettings());
|
||||
|
||||
LineCol oldCaretPosition = LineCol.fromOffset(myDocument, myEditor.getCaretModel().getPrimaryCaret().getOffset());
|
||||
Pair<int[], Side> oldCaretLineTwoside = transferLineFromOneside(oldCaretPosition.line);
|
||||
|
||||
|
||||
clearDiffPresentation();
|
||||
|
||||
|
||||
if (isContentsEqual) {
|
||||
boolean equalCharsets = TextDiffViewerUtil.areEqualCharsets(getContents());
|
||||
boolean equalSeparators = TextDiffViewerUtil.areEqualLineSeparators(getContents());
|
||||
@@ -431,8 +437,14 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase {
|
||||
guarderRangeBlocks.add(createGuardedBlock(textLength, textLength));
|
||||
}
|
||||
|
||||
|
||||
myChangedBlockData = new ChangedBlockData(diffChanges, guarderRangeBlocks, convertor, isContentsEqual);
|
||||
|
||||
|
||||
int newCaretLine = transferLineToOneside(oldCaretLineTwoside.second,
|
||||
oldCaretLineTwoside.second.select(oldCaretLineTwoside.first));
|
||||
myEditor.getCaretModel().moveToOffset(LineCol.toOffset(myDocument, newCaretLine, oldCaretPosition.column));
|
||||
|
||||
myFoldingModel.install(changedLines, myRequest, getFoldingModelSettings());
|
||||
|
||||
myInitialScrollHelper.onRediff();
|
||||
|
||||
Reference in New Issue
Block a user