Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1139,4 +1139,30 @@ public void testIsAnsiEscapeEnabled() throws ExecutionException, NotDefinedExcep
final boolean changedBack = IOConsole.isAnsiConsoleEnabled();
assertEquals(initial, changedBack);
}


@Test
public void testBug2127_CaretRepositionedAfterOutput() throws Exception {
IOConsoleTestUtil c = getTestUtil("Test caret reposition after output");
try {
c.writeAndVerify("Please type something: ");
c.insertTypingAndVerify("42");
c.enter();
TestUtil.waitWhile(() -> c.getCaretOffset() != c.getContentLength(), TestUtil.DEFAULT_TIMEOUT, () -> "Caret never reached end of document after submitting input.");

int caretBeforeOutput = c.getCaretOffset();
c.writeAndVerify("You typed: 42");
TestUtil.waitWhile(() -> c.getCaretOffset() != c.getContentLength(), TestUtil.DEFAULT_TIMEOUT, () -> "Caret was not repositioned to end of document after output arrived at the old (now read-only) caret position.");

assertTrue(c.getPartitioner().isReadOnly(caretBeforeOutput), "Precondition: old caret position must now be read-only.");

c.insertTypingAndVerify("7");
c.enter().clear();
c.verifyPartitions();
closeConsole(c, "42", "7");
} finally {
ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {
c.getConsole() });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -225,10 +225,43 @@ public void documentAboutToBeChanged(DocumentEvent event) {
public void documentChanged(DocumentEvent event) {
if (fAutoScroll) {
revealEndOfDocument();
repositionCaretAfterOutput();
}
}
};
}
return fAutoScrollListener;
}

/**
* Moves caret to the beginning of next valid input section
*/
private void repositionCaretAfterOutput() {
final IDocument doc = getDocument();
if (doc == null) {
return;
}
if (doc.getDocumentPartitioner() instanceof IConsoleDocumentPartitioner consolePart
&& consolePart instanceof IConsoleDocumentPartitionerExtension consolePartExt) {
StyledText widget = getTextWidget();
if (widget == null || widget.isDisposed()) {
return;
}
ConsolePlugin.getStandardDisplay().asyncExec(() -> {
StyledText styleText = getTextWidget();
if (styleText == null || styleText.isDisposed()) {
return;
}
int caretOffset = widget.getCaretOffset();
Comment thread
SougandhS marked this conversation as resolved.
if (consolePart.isReadOnly(caretOffset) && consolePart.isReadOnly(Math.max(caretOffset - 1, 0))) {
int nextWritable = consolePartExt.getNextOffsetByState(caretOffset, true);
if (nextWritable != caretOffset) {
styleText.setCaretOffset(nextWritable);
styleText.showSelection();
}
}
});
}

}
}
Loading