groovy

Multiline text selection not handled correctly in GroovyConsole on execution (Windows only bug)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.1-rc-1
  • Fix Version/s: 1.1-rc-2
  • Component/s: Groovysh
  • Labels:
    None
  • Environment:
    Windows bug only
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

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

Activity

Hide
Paul King added a comment -

Fixed in HEAD

Show
Paul King added a comment - Fixed in HEAD

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: