]> git.lyx.org Git - features.git/commitdiff
* LyXRC.cpp:
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 1 Jul 2008 14:42:32 +0000 (14:42 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 1 Jul 2008 14:42:32 +0000 (14:42 +0000)
* development/MacOSX/lyxrc.dist.in: new variable mac_like_word_movement,
set to true on Mac OS X. There is no GUI for it now.

* src/Paragraph.cpp (isSpace): new method
(isChar): return false for a space.

* src/Text.cpp (cursorForwardOneWord, cursorBackWardOneWord): implement
mac-like cursor movement.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25413 a592a061-630c-0410-9148-cb99ea01b6c8

development/MacOSX/lyxrc.dist.in
src/LyXRC.cpp
src/LyXRC.h
src/Paragraph.cpp
src/Paragraph.h
src/Text.cpp

index c67f0afa6e5cda57d26526ec24940bfa98560095..0ee4aac593ce28f837fa192142b0b19204003dfe 100644 (file)
@@ -28,6 +28,7 @@
 \screen_font_sans "Helvetica"
 \screen_font_typewriter "Courier"
 \open_buffers_in_tabs false
+\mac_like_word_movement true
 
 #
 # COLOR SECTION ###################################
index 64d18fa590818c251ee0ab4d4116ae1ee5d4bbb6..3f9366cb044a73234ca9c23ec226cdd0a97526e4 100644 (file)
@@ -111,6 +111,7 @@ LexerKeyword lyxrcTags[] = {
        { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE },
        { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL },
        { "\\load_session", LyXRC::RC_LOADSESSION },
+       { "\\mac_like_word_movement", LyXRC::RC_MAC_LIKE_WORD_MOVEMENT },
        { "\\macro_edit_style", LyXRC::RC_MACRO_EDIT_STYLE },
        { "\\make_backup", LyXRC::RC_MAKE_BACKUP },
        { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE },
@@ -285,6 +286,7 @@ void LyXRC::setDefaults()
        tex_allows_spaces = false;
        date_insert_format = "%x";
        cursor_follows_scrollbar = false;
+       mac_like_word_movement = false;
        macro_edit_style = MACRO_EDIT_INLINE_BOX;
        dialogs_iconify_with_main = false;
        label_init_length = 3;
@@ -800,6 +802,10 @@ int LyXRC::read(Lexer & lexrc)
                        lexrc >> cursor_follows_scrollbar;
                        break;
 
+               case RC_MAC_LIKE_WORD_MOVEMENT:
+                       lexrc >> mac_like_word_movement;
+                       break;
+
                case RC_MACRO_EDIT_STYLE:
                        if (lexrc.next()) {
                                switch (lexrc.getInteger()) {
@@ -1488,6 +1494,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
+       case RC_MAC_LIKE_WORD_MOVEMENT:
+               if (ignore_system_lyxrc ||
+                   mac_like_word_movement
+                   != system_lyxrc.mac_like_word_movement) {
+                       os << "\\mac_like_word_movement "
+                          << convert<string>(mac_like_word_movement) << '\n';
+               }
+               if (tag != RC_LAST)
+                       break;
        case RC_MACRO_EDIT_STYLE:
                if (ignore_system_lyxrc ||
                    macro_edit_style
@@ -2457,6 +2472,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = _("LyX normally doesn't update the cursor position if you move the scrollbar. Set to true if you'd prefer to always have the cursor on screen.");
                break;
 
+       case RC_MAC_LIKE_WORD_MOVEMENT:
+               str = _("Use the Mac OS X conventions for the word-level cursor movement");
+               break;
+
        case RC_SHOW_MACRO_LABEL:
                str = _("Show a small box around a Math Macro with the macro name when the cursor is inside.");
                break;
index e51c233ed94e5abb8fdf368f6551e7eafaf6ca7c..ae9ab388c93907655fccfdb260a0ba4bd0484543 100644 (file)
@@ -62,6 +62,7 @@ public:
                RC_CONVERTER_CACHE_MAXAGE,
                RC_COPIER,
                RC_CURSOR_FOLLOWS_SCROLLBAR,
+               RC_MAC_LIKE_WORD_MOVEMENT,
                RC_CUSTOM_EXPORT_COMMAND,
                RC_CUSTOM_EXPORT_FORMAT,
                RC_DATE_INSERT_FORMAT,
@@ -365,6 +366,8 @@ public:
        ///
        std::string gui_language;
        ///
+       bool mac_like_word_movement;
+       ///
        bool cursor_follows_scrollbar;
        ///
        enum MacroEditStyle {
index 5eb3a67462416adf0b19bc9d5882acd8e5392eed..5fae6cf97e52837f2c852b8ba744894d9d333930 100644 (file)
@@ -2273,7 +2273,16 @@ bool Paragraph::isChar(pos_type pos) const
        if (Inset const * inset = getInset(pos))
                return inset->isChar();
        char_type const c = d->text_[pos];
-       return !isLetterChar(c) && !isDigit(c);
+       return !isLetterChar(c) && !isDigit(c) && !lyx::isSpace(c);
+}
+
+
+bool Paragraph::isSpace(pos_type pos) const
+{
+       if (Inset const * inset = getInset(pos))
+               return inset->isSpace();
+       char_type const c = d->text_[pos];
+       return lyx::isSpace(c);
 }
 
 
index 267fc8de60f6a8cec363a0e0cb8f6277b1932724..ac95de18e8a3d745eac5d8069fa59242b080cfe2 100644 (file)
@@ -336,6 +336,8 @@ public:
        bool isLetter(pos_type pos) const;
        /// True if the element at this point is a character that is not a letter.
        bool isChar(pos_type pos) const;
+       /// True if the element at this point is a space
+       bool isSpace(pos_type pos) const;
 
        /// returns true if at least one line break or line separator has been deleted
        /// at the beginning of the paragraph (either physically or logically)
index b655830651bda24d2be87b80a4a50da7c56350d0..44de33c46a7e2f714dd1a6efbeb3daa6c603f24a 100644 (file)
@@ -590,18 +590,37 @@ bool Text::cursorForwardOneWord(Cursor & cur)
        Paragraph const & par = cur.paragraph();
 
        // Paragraph boundary is a word boundary
-       if (pos == lastpos && pit != cur.lastpit())
-               return setCursor(cur, pit + 1, 0);
+       if (pos == lastpos)
+               if (pit != cur.lastpit())
+                       return setCursor(cur, pit + 1, 0);
+               else
+                       return false;
+
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through trailing punctuation and spaces.
+               while (pos != lastpos && par.isChar(pos))
+                        ++pos;
 
-       // Skip over either a non-char inset or a full word
-       if (pos != lastpos && !par.isLetter(pos) && !par.isChar(pos))
-               ++pos;
-       else while (pos != lastpos && par.isLetter(pos))
+               // Skip over either a non-char inset or a full word
+               if (pos != lastpos && !par.isLetter(pos))
+                       ++pos;
+               else while (pos != lastpos && par.isLetter(pos))
+                            ++pos;
+       } else {
+               LASSERT(pos < lastpos, /**/); // see above
+               if (par.isLetter(pos))
+                       while (pos != lastpos && par.isLetter(pos))
+                               ++pos;
+               else if (par.isChar(pos))
+                       while (pos != lastpos && par.isChar(pos))
+                               ++pos;
+               else if (!par.isSpace(pos)) // non-char inset
                        ++pos;
 
-       // Skip through trailing punctuation and spaces.
-       while (pos != lastpos && par.isChar(pos))
-               ++pos;
+               // Skip over white space
+               while (pos != lastpos && par.isSpace(pos))
+                            ++pos;             
+       }
 
        return setCursor(cur, pit, pos);
 }
@@ -619,15 +638,30 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
        if (pos == 0 && pit != 0)
                return setCursor(cur, pit - 1, getPar(pit - 1).size());
 
-       // Skip through puctuation and spaces.
-       while (pos != 0 && par.isChar(pos - 1))
-               --pos;
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through puctuation and spaces.
+               while (pos != 0 && par.isChar(pos - 1))
+                       --pos;
 
-       // Skip over either a non-char inset or a full word
-       if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
-               --pos;
-       else while (pos != 0 && par.isLetter(pos - 1))
+               // Skip over either a non-char inset or a full word
+               if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
                        --pos;
+               else while (pos != 0 && par.isLetter(pos - 1))
+                            --pos;
+       } else {
+               // Skip over white space
+               while (pos != 0 && par.isSpace(pos - 1))
+                            --pos;
+
+               if (pos != 0 && par.isLetter(pos - 1))
+                       while (pos != 0 && par.isLetter(pos - 1))
+                               --pos;
+               else if (pos != 0 && par.isChar(pos - 1))
+                       while (pos != 0 && par.isChar(pos - 1))
+                               --pos;
+               else if (pos != 0 && !par.isSpace(pos - 1)) // non-char inset
+                       --pos;
+       }
 
        return setCursor(cur, pit, pos);
 }