Eclipse IConsole Caret Position

I am implementing an Eclipse plugin with IOConsole, which receives keyboard input and produces output (IOConsoleInputStream, IOConsoleOutputStream). I try to always put the carriage on the last character by expanding the TextConsoleViewer as suggested here

How to install Caret IOConsole

The problem is that when the time to change the position of the carriage after the printed output, the character that is written by another stream that has a link to the output stream is not counted as the number of characters in the console.

here is the link to my code

https://code.google.com/p/mdpm/source/browse/com.lowcoupling.mdpm.console/src/com/lowcoupling/mdpm/console/MDPMConsole.java

thanks

+4
source share
1 answer

The source code for setCaretOffset() shows that if you use an offset greater than the length of the text, then instead the length of the text is used, almost putting the caret at the end of the text. Therefore, setting Integer.MAX_VALUE as an offset is a viable option, without requiring any text length checks.

If you can’t get a notification when the flushing has really ended, I suggest that you postpone the carriage placement for a few hundred milliseconds. It will not be distracting for the user and provides a reliable solution for you.

For reference, here is the source code for setCaretOffset() :

 public void setCaretOffset(int offset) { checkWidget(); int length = getCharCount(); if (length > 0 && offset != caretOffset) { if (offset < 0) { offset = 0; } else if (offset > length) { offset = length; // <-- use the length as offset } else { if (isLineDelimiter(offset)) { // offset is inside a multi byte line delimiter. This is an // illegal operation and an exception is thrown. Fixes 1GDKK3R SWT.error(SWT.ERROR_INVALID_ARGUMENT); } } setCaretOffset(offset, PREVIOUS_OFFSET_TRAILING); // clear the selection if the caret is moved. // don't notify listeners about the selection change. if (blockSelection) { clearBlockSelection(true, false); } else { clearSelection(false); } } setCaretLocation(); } 
+2
source

Source: https://habr.com/ru/post/1501404/


All Articles