OmarEmaraDev created this revision. OmarEmaraDev added a reviewer: clayborg. Herald added a reviewer: teemperor. OmarEmaraDev requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
This patch handles the return key for compound fields like lists and mapping fields. The return key, if not handled by the field will select the next primary element, skipping secondary elements like remove buttons and the like. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D108331 Files: lldb/source/Core/IOHandlerCursesGUI.cpp Index: lldb/source/Core/IOHandlerCursesGUI.cpp =================================================================== --- lldb/source/Core/IOHandlerCursesGUI.cpp +++ lldb/source/Core/IOHandlerCursesGUI.cpp @@ -1816,6 +1816,31 @@ return eKeyHandled; } + // If the last element of the field is selected and it didn't handle the key. + // Select the next field or new button if the selected field is the last one. + HandleCharResult SelectNextInList(int key) { + assert(m_selection_type == SelectionType::Field); + + FieldDelegate &field = m_fields[m_selection_index]; + if (field.FieldDelegateHandleChar(key) == eKeyHandled) + return eKeyHandled; + + if (!field.FieldDelegateOnLastOrOnlyElement()) + return eKeyNotHandled; + + field.FieldDelegateExitCallback(); + + if (m_selection_index == GetNumberOfFields() - 1) { + m_selection_type = SelectionType::NewButton; + return eKeyHandled; + } + + m_selection_index++; + FieldDelegate &next_field = m_fields[m_selection_index]; + next_field.FieldDelegateSelectFirstElement(); + return eKeyHandled; + } + HandleCharResult FieldDelegateHandleChar(int key) override { switch (key) { case '\r': @@ -1828,16 +1853,14 @@ case SelectionType::RemoveButton: RemoveField(); return eKeyHandled; - default: - break; + case SelectionType::Field: + return SelectNextInList(key); } break; case '\t': - SelectNext(key); - return eKeyHandled; + return SelectNext(key); case KEY_SHIFT_TAB: - SelectPrevious(key); - return eKeyHandled; + return SelectPrevious(key); default: break; } @@ -1984,14 +2007,34 @@ return eKeyHandled; } + // If the value field is selected, pass the key to it. If the key field is + // selected, its last element is selected, and it didn't handle the key, then + // select its corresponding value field. + HandleCharResult SelectNextField(int key) { + if (m_selection_type == SelectionType::Value) { + return m_value_field.FieldDelegateHandleChar(key); + } + + if (m_key_field.FieldDelegateHandleChar(key) == eKeyHandled) + return eKeyHandled; + + if (!m_key_field.FieldDelegateOnLastOrOnlyElement()) + return eKeyNotHandled; + + m_key_field.FieldDelegateExitCallback(); + m_selection_type = SelectionType::Value; + m_value_field.FieldDelegateSelectFirstElement(); + return eKeyHandled; + } + HandleCharResult FieldDelegateHandleChar(int key) override { switch (key) { + case KEY_RETURN: + return SelectNextField(key); case '\t': - SelectNext(key); - return eKeyHandled; + return SelectNext(key); case KEY_SHIFT_TAB: - SelectPrevious(key); - return eKeyHandled; + return SelectPrevious(key); default: break; }
Index: lldb/source/Core/IOHandlerCursesGUI.cpp =================================================================== --- lldb/source/Core/IOHandlerCursesGUI.cpp +++ lldb/source/Core/IOHandlerCursesGUI.cpp @@ -1816,6 +1816,31 @@ return eKeyHandled; } + // If the last element of the field is selected and it didn't handle the key. + // Select the next field or new button if the selected field is the last one. + HandleCharResult SelectNextInList(int key) { + assert(m_selection_type == SelectionType::Field); + + FieldDelegate &field = m_fields[m_selection_index]; + if (field.FieldDelegateHandleChar(key) == eKeyHandled) + return eKeyHandled; + + if (!field.FieldDelegateOnLastOrOnlyElement()) + return eKeyNotHandled; + + field.FieldDelegateExitCallback(); + + if (m_selection_index == GetNumberOfFields() - 1) { + m_selection_type = SelectionType::NewButton; + return eKeyHandled; + } + + m_selection_index++; + FieldDelegate &next_field = m_fields[m_selection_index]; + next_field.FieldDelegateSelectFirstElement(); + return eKeyHandled; + } + HandleCharResult FieldDelegateHandleChar(int key) override { switch (key) { case '\r': @@ -1828,16 +1853,14 @@ case SelectionType::RemoveButton: RemoveField(); return eKeyHandled; - default: - break; + case SelectionType::Field: + return SelectNextInList(key); } break; case '\t': - SelectNext(key); - return eKeyHandled; + return SelectNext(key); case KEY_SHIFT_TAB: - SelectPrevious(key); - return eKeyHandled; + return SelectPrevious(key); default: break; } @@ -1984,14 +2007,34 @@ return eKeyHandled; } + // If the value field is selected, pass the key to it. If the key field is + // selected, its last element is selected, and it didn't handle the key, then + // select its corresponding value field. + HandleCharResult SelectNextField(int key) { + if (m_selection_type == SelectionType::Value) { + return m_value_field.FieldDelegateHandleChar(key); + } + + if (m_key_field.FieldDelegateHandleChar(key) == eKeyHandled) + return eKeyHandled; + + if (!m_key_field.FieldDelegateOnLastOrOnlyElement()) + return eKeyNotHandled; + + m_key_field.FieldDelegateExitCallback(); + m_selection_type = SelectionType::Value; + m_value_field.FieldDelegateSelectFirstElement(); + return eKeyHandled; + } + HandleCharResult FieldDelegateHandleChar(int key) override { switch (key) { + case KEY_RETURN: + return SelectNextField(key); case '\t': - SelectNext(key); - return eKeyHandled; + return SelectNext(key); case KEY_SHIFT_TAB: - SelectPrevious(key); - return eKeyHandled; + return SelectPrevious(key); default: break; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits