void SourceEditor::activateAction(Window &window, GtkAction *action, Actions::ActionIndex index) { switch (index) { case Actions::ACTION_INDENT: { int line, column, line2, column2; getSelectedRange(line, column, line2, column2); if (line == line2 && column == column2) static_cast<SourceFile &>(file()).indent(line, line + 1, line); else { if (line2 < line || (line2 == line && column2 < column)) { std::swap(line, line2); std::swap(column, column2); } if (column2 == 0) static_cast<SourceFile &>(file()).indent(line, line2, -1); else static_cast<SourceFile &>(file()). indent(line, line2 + 1, -1); } return; } } TextEditor::activateAction(window, action, index); }
void TextField::backspace(g_key_info& info) { if (text.length() > 0) { g_range selected = getSelectedRange(); int leftcut = selected.getFirst(); if (info.alt) { leftcut = cursorMoveStrategy->calculateSkip(text, leftcut, CursorDirection::LEFT); } else if (info.ctrl) { leftcut = 0; } int rightcut = selected.getLast(); if (rightcut - leftcut == 0) { leftcut--; } if (leftcut >= 0 && rightcut <= text.length()) { std::string beforeCursor = text.substr(0, leftcut); std::string afterCursor = text.substr(rightcut); text = beforeCursor + afterCursor; setCursor(leftcut); setMarker(leftcut); markFor(COMPONENT_REQUIREMENT_UPDATE); } } }
void TextField::insert(std::string ins) { g_range selected = getSelectedRange(); int first = selected.getFirst(); int last = selected.getLast(); if (first < 0) { first = 0; } if (last > text.size()) { last = text.size(); } std::string beforeCursor = text.substr(0, first); std::string afterCursor = text.substr(last); text = beforeCursor + ins + afterCursor; setCursor(first + ins.length()); setMarker(first + ins.length()); markFor(COMPONENT_REQUIREMENT_UPDATE); }