Changeset cf592af in OpenModelica


Ignore:
Timestamp:
2017-02-23T15:32:21+01:00 (7 years ago)
Author:
Adeel Asghar <adeel.asghar@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
d3844f3
Parents:
b6f72c5
Message:

ticket:3964 Handle the home key.
Move the cursor to the start of the line from where the text starts.
Skip the trailing spaces.

Location:
OMEdit/OMEditGUI/Editors
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditGUI/Editors/BaseEditor.cpp

    r2702730 rcf592af  
    11621162
    11631163/*!
     1164 * \brief BaseEditor::PlainTextEdit::handleHomeKey
     1165 * Handles the home key.\n
     1166 * Moves the cursor to the start of the line.\n
     1167 * Skips the trailing spaces.
     1168 * \param keepAnchor
     1169 */
     1170void BaseEditor::PlainTextEdit::handleHomeKey(bool keepAnchor)
     1171{
     1172  QTextCursor cursor = textCursor();
     1173  QTextCursor::MoveMode mode = keepAnchor ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor;
     1174  const int initpos = cursor.position();
     1175  int pos = cursor.block().position();
     1176  QChar character = document()->characterAt(pos);
     1177  const QLatin1Char tab = QLatin1Char('\t');
     1178  // loop until we have some character
     1179  while (character == tab || character.category() == QChar::Separator_Space) {
     1180    ++pos;
     1181    if (pos == initpos) {
     1182      break;
     1183    }
     1184    character = document()->characterAt(pos);
     1185  }
     1186  // Go to the start of the block when we're already at the start of the text
     1187  if (pos == initpos) {
     1188    pos = cursor.block().position();
     1189  }
     1190  // set the cursor position
     1191  cursor.setPosition(pos, mode);
     1192  setTextCursor(cursor);
     1193}
     1194
     1195/*!
    11641196 * \brief BaseEditor::PlainTextEdit::highlightCurrentLine
    11651197 * Hightlights the current line.
     
    12371269
    12381270/*!
    1239  * \brief BaseEditor::keyPressEvent
     1271 * \brief BaseEditor::PlainTextEdit::keyPressEvent
    12401272 * Reimplementation of keyPressEvent.
    12411273 * \param pEvent
     
    12431275void BaseEditor::PlainTextEdit::keyPressEvent(QKeyEvent *pEvent)
    12441276{
     1277  bool shiftModifier = pEvent->modifiers().testFlag(Qt::ShiftModifier);
     1278  bool controlModifier = pEvent->modifiers().testFlag(Qt::ControlModifier);
    12451279  if (pEvent->key() == Qt::Key_Escape) {
    12461280    if (mpBaseEditor->getFindReplaceWidget()->isVisible()) {
     
    12531287    indentOrUnindent(pEvent->key() == Qt::Key_Tab);
    12541288    return;
    1255   } else if (pEvent->modifiers().testFlag(Qt::ControlModifier) && pEvent->key() == Qt::Key_F) {
     1289  } else if (controlModifier && pEvent->key() == Qt::Key_F) {
    12561290    // ctrl+f is pressed.
    12571291    mpBaseEditor->showFindReplaceWidget();
    12581292    return;
    1259   } else if (pEvent->modifiers().testFlag(Qt::ControlModifier) && pEvent->key() == Qt::Key_L) {
     1293  } else if (controlModifier && pEvent->key() == Qt::Key_L) {
    12601294    // ctrl+l is pressed.
    12611295    mpBaseEditor->showGotoLineNumberDialog();
    12621296    return;
    1263   } else if (pEvent->modifiers().testFlag(Qt::ControlModifier) && pEvent->key() == Qt::Key_K) {
     1297  } else if (controlModifier && pEvent->key() == Qt::Key_K) {
    12641298    // ctrl+k is pressed.
    12651299    mpBaseEditor->toggleCommentSelection();
    12661300    return;
    1267 //  } else if (pEvent->modifiers().testFlag(Qt::ControlModifier) && pEvent->key() == Qt::Key_Plus) {
    1268 //    // ctrl++ is pressed.
    1269 //    zoomIn();
    1270 //    return;
    1271 //  } else if (pEvent->modifiers().testFlag(Qt::ControlModifier) && pEvent->key() == Qt::Key_Underscore) {
    1272 //    // ctrl+- is pressed.
    1273 //    zoomOut();
    1274 //    return;
    1275 //  } else if (pEvent->modifiers().testFlag(Qt::ControlModifier) && pEvent->key() == Qt::Key_0) {
    1276 //    // ctrl+0 is pressed.
    1277 //    resetZoom();
    1278 //    return;
    1279   } else if (pEvent->modifiers().testFlag(Qt::ShiftModifier) && (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return)) {
     1301  } else if (shiftModifier && pEvent->key() == Qt::Key_Home) {
     1302    handleHomeKey(true);
     1303    return;
     1304  } else if (pEvent->key() == Qt::Key_Home) {
     1305    handleHomeKey(false);
     1306    return;
     1307  } else if (shiftModifier && (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return)) {
    12801308    /* Ticket #2273. Change shift+enter to enter. */
    12811309    pEvent->setModifiers(Qt::NoModifier);
  • OMEdit/OMEditGUI/Editors/BaseEditor.h

    r2702730 rcf592af  
    235235    void zoomIn();
    236236    void zoomOut();
     237    void handleHomeKey(bool keepAnchor);
    237238  private:
    238239    BaseEditor *mpBaseEditor;
Note: See TracChangeset for help on using the changeset viewer.