Hi!

Here's another patch I have in the works. I only recently was finally able to reliably reproduce it, and once I understood what the problem is, the fix is fairly easy. However, I may very well not be aware of all the aspects of keymaps, so please look at this carefully.

To see the bug, you have to have use two keymaps, otherwise it's a little hard... To setup another keymap: Preferences -> Look and feel -> Keyboard -> check "Use keyboard map", and then enter "null" as the First and "hebrew" as the second (I'm going to be talking about English and Hebrew, because those are the languages I use). Then switching languages between hebrew and english (which is achieved by typing "language hebrew" in the minibuffer; F12 is the binding for that in the Hebrew setup) also switches the keymap. Finally, you may or may not see hebrew, depending on the screen font you're using; but even if you don't, you should see a square or something instead of the Hebrew, which is good enough for our current purposes...

So, here we go:

type some English. Then switch languages, and type some Hebrew. Then, switch languages again, and type some more in English. Now, with the LEFT/RIGHT keys, move the cursor into a region of the opposite language in which you currently are. Now, the first character you type will be in the correct (i.e., new region's) language, but the keymap doesn't take effect. Type in more characters, and it's already okay.

So the problem is, the keymap is somehow only kicking in after the first key is typed.

My solution is in the attached patch. AFAIU, the keymap only affects the interpretation of the keys typed in. So it seems to make sense to add it where I did. OTOH, I don't see why it's necessary in any of the other places anymore, so I removed them all, and so far it seems to be okay. I don't know why there was an attempt to do it the current way --- it seems like there's a lot more maintenance involved, making sure that whenever you move, the keymap is updated --- and some things get forgotten, like cursor movement did now... Now, by just switching the keymap just before its needed for the interpretation of the key, there's nothing to keep track of.

Does this seem okay, and if so --- could someone please commit?

Thanks!
Dov

Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp  (revision 18642)
+++ src/BufferView.cpp  (working copy)
@@ -313,7 +313,6 @@
        LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION << endl;
 
        updateMetrics(false);
-       switchKeyMap();
 }
 
 
@@ -774,7 +773,6 @@
                        cur.message(_("No further undo information"));
                        updateFlags = Update::None;
                }
-               switchKeyMap();
                break;
 
        case LFUN_REDO:
@@ -784,7 +782,6 @@
                        cur.message(_("No further redo information"));
                        updateFlags = Update::None;
                }
-               switchKeyMap();
                break;
 
        case LFUN_FILE_INSERT:
@@ -846,7 +843,6 @@
                                if (b == buffer_) {
                                        // Set the cursor
                                        setCursor(makeDocIterator(par, 0));
-                                       switchKeyMap();
                                } else {
                                        // Switch to other buffer view and 
resend cmd
                                        theLyXFunc().dispatch(FuncRequest(
Index: src/mathed/InsetMathGrid.cpp
===================================================================
--- src/mathed/InsetMathGrid.cpp        (revision 18642)
+++ src/mathed/InsetMathGrid.cpp        (working copy)
@@ -1208,7 +1208,6 @@
                                        cell(i).append(grid.cell(grid.index(r, 
c)));
                }
                cur.clearSelection(); // bug 393
-               cur.bv().switchKeyMap();
                finishUndo();
                break;
        }
Index: src/mathed/InsetMathNest.cpp
===================================================================
--- src/mathed/InsetMathNest.cpp        (revision 18642)
+++ src/mathed/InsetMathNest.cpp        (working copy)
@@ -450,7 +450,6 @@
                }
                cur.niceInsert(topaste);
                cur.clearSelection(); // bug 393
-               cur.bv().switchKeyMap();
                finishUndo();
                break;
        }
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp       (revision 18642)
+++ src/Text3.cpp       (working copy)
@@ -124,7 +124,6 @@
                if (selecting || cur.mark())
                        cur.setSelection();
                saveSelection(cur);
-               cur.bv().switchKeyMap();
        }
 
 
@@ -634,7 +633,6 @@
                        cutSelection(cur, true, false);
                        singleParUpdate = false;
                }
-               bv->switchKeyMap();
                break;
 
        case LFUN_DELETE_BACKWARD_SKIP:
@@ -655,14 +653,12 @@
                cap::replaceSelection(cur);
                breakParagraph(cur, 0);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
 
        case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
                cap::replaceSelection(cur);
                breakParagraph(cur, 1);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
 
        case LFUN_BREAK_PARAGRAPH_SKIP: {
@@ -674,7 +670,6 @@
                else
                        breakParagraph(cur, 0);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
        }
 
@@ -817,7 +812,6 @@
                }
                bv->buffer()->errors("Paste");
                cur.clearSelection(); // bug 393
-               bv->switchKeyMap();
                finishUndo();
                break;
 
@@ -908,7 +902,6 @@
                        setLayout(cur, layout);
                        // inform the GUI that the layout has changed.
                        bv->layoutChanged(layout);
-                       bv->switchKeyMap();
                }
                break;
        }
@@ -1030,7 +1023,6 @@
                                cap::pasteSelection(cur, 
bv->buffer()->errorList("Paste"));
                                bv->buffer()->errors("Paste");
                                cur.clearSelection(); // bug 393
-                               bv->switchKeyMap();
                                bv->buffer()->markDirty();
                                finishUndo();
                        } else
@@ -1109,7 +1101,6 @@
                        cur.noUpdate();
                }
 
-               bv->switchKeyMap();
                break;
        }
 
@@ -1130,6 +1121,7 @@
                cur.clearSelection();
                Font const old_font = real_current_font;
 
+               bv->switchKeyMap();
                docstring::const_iterator cit = cmd.argument().begin();
                docstring::const_iterator end = cmd.argument().end();
                for (; cit != end; ++cit)
@@ -1402,7 +1394,6 @@
                Font font(Font::ALL_IGNORE);
                font.setLanguage(lang);
                toggleAndShow(cur, this, font);
-               bv->switchKeyMap();
                break;
        }
 

Reply via email to