diff options
Diffstat (limited to 'source/Host/common/Editline.cpp')
-rw-r--r-- | source/Host/common/Editline.cpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/source/Host/common/Editline.cpp b/source/Host/common/Editline.cpp index ed67d0c2c2b3..4640154c6cb1 100644 --- a/source/Host/common/Editline.cpp +++ b/source/Host/common/Editline.cpp @@ -203,7 +203,7 @@ namespace lldb_private { snprintf (history_path, sizeof (history_path), "~/%s-widehistory", m_prefix.c_str()); } - m_path = std::move (FileSpec (history_path, true).GetPath()); + m_path = FileSpec (history_path, true).GetPath(); } if (m_path.empty()) return NULL; @@ -863,34 +863,50 @@ Editline::NextLineCommand (int ch) unsigned char Editline::FixIndentationCommand (int ch) { - if (!m_fix_indentation_callback) + if (!m_fix_indentation_callback) return CC_NORM; - - // Insert the character by hand prior to correction + + // Insert the character typed before proceeding EditLineCharType inserted[] = { (EditLineCharType)ch, 0 }; el_winsertstr (m_editline, inserted); - SaveEditedLine(); - StringList lines = GetInputAsStringList (m_current_line_index + 1); - - // Determine the cursor position LineInfoW * info = const_cast<LineInfoW *>(el_wline (m_editline)); int cursor_position = info->cursor - info->buffer; - + + // Save the edits and determine the correct indentation level + SaveEditedLine(); + StringList lines = GetInputAsStringList (m_current_line_index + 1); int indent_correction = m_fix_indentation_callback (this, lines, cursor_position, m_fix_indentation_callback_baton); - - // Adjust the input buffer to correct indentation + + // If it is already correct no special work is needed + if (indent_correction == 0) + return CC_REFRESH; + + // Change the indentation level of the line + std::string currentLine = lines.GetStringAtIndex (m_current_line_index); if (indent_correction > 0) { - info->cursor = info->buffer; - el_winsertstr (m_editline, EditLineStringType (indent_correction, EditLineCharType(' ')).c_str()); + currentLine = currentLine.insert (0, indent_correction, ' '); } - else if (indent_correction < 0) + else { - info->cursor = info->buffer - indent_correction; - el_wdeletestr (m_editline, -indent_correction); + currentLine = currentLine.erase (0, -indent_correction); } - info->cursor = info->buffer + cursor_position + indent_correction; - return CC_REFRESH; +#if LLDB_EDITLINE_USE_WCHAR + m_input_lines[m_current_line_index] = m_utf8conv.from_bytes (currentLine); +#else + m_input_lines[m_current_line_index] = currentLine; +#endif + + // Update the display to reflect the change + MoveCursor (CursorLocation::EditingCursor, CursorLocation::EditingPrompt); + DisplayInput (m_current_line_index); + + // Reposition the cursor back on the original line and prepare to restart editing + // with a new cursor position + SetCurrentLine (m_current_line_index); + MoveCursor (CursorLocation::BlockEnd, CursorLocation::EditingPrompt); + m_revert_cursor_index = cursor_position + indent_correction; + return CC_NEWLINE; } unsigned char |