From 0903e028aaf5e3023b5aff6cfbab60d21cc39221 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Sat, 3 Apr 2021 10:08:53 +0200 Subject: [PATCH] FIRE-30892: Improved Home key behavior in script editor: Move cursor to first non-whitespace character on first press, then toggle between start of line and first non-whitespace character as seen in various editors --- indra/newview/llscripteditor.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index b020d52c0b..82f288824f 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -327,19 +327,32 @@ void LLScriptEditor::drawSelectionBackground() //virtual void LLScriptEditor::startOfLine() { - const LLWString text = getWText(); + const LLWString& text = getWText(); const S32 line_start_pos = mCursorPos - getLineOffsetFromDocIndex(mCursorPos); + + S32 line_end_pos; + S32 line = getLineNumFromDocIndex(mCursorPos); + S32 num_lines = getLineCount(); + if (line + 1 >= num_lines) + { + line_end_pos = getLength(); + } + else + { + line_end_pos = getLineStart(line + 1) - 1; + } + S32 trimmed_line_start_pos = line_start_pos; - while (trimmed_line_start_pos < mCursorPos && LLStringOps::isSpace(text[trimmed_line_start_pos])) + while (trimmed_line_start_pos < line_end_pos && LLStringOps::isSpace(text[trimmed_line_start_pos])) { ++trimmed_line_start_pos; } - if (mCursorPos != trimmed_line_start_pos) + if (mCursorPos != trimmed_line_start_pos || mCursorPos == line_start_pos) { setCursorPos(trimmed_line_start_pos); } - else if (mCursorPos != line_start_pos) + else if (mCursorPos == trimmed_line_start_pos) { setCursorPos(line_start_pos); }