Details
Description
Internally, java.text.Document stores text per *nix style (i.e. '\n' only line separator), but the getText() method returns the text using the operating systems line separator ('\r\n' on windows). The console stores whatever text is in the buffer for each execution, and instead of storing the selected text it stores the indexes of the start and end of the current selection. Unfortunately, those latter values are lost in translation. The solution I used was to replace the OS line separator with a standard '\n' for the purpose of history tracking, and this cleared up the problem.
Old code in Console.groovy:
void runScript(EventObject evt = null) {
def record = new HistoryRecord( allText: inputArea.getText(), selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
addToHistory(record)
// ... executes script after this
Proposed new code:
void runScript(EventObject evt = null) {
def endLine = System.getProperty('line.separator')
def record = new HistoryRecord( allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart,
selectionEnd: textSelectionEnd)
addToHistory(record)
// ... executes script after this