]> git.lyx.org Git - lyx.git/blob - src/text3.C
A couple of changing resulting from gcc 3.4 debug mode testing.
[lyx.git] / src / text3.C
1 /**
2  * \file text3.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "lyxtext.h"
19
20 #include "buffer.h"
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "cursor.h"
24 #include "debug.h"
25 #include "dispatchresult.h"
26 #include "factory.h"
27 #include "funcrequest.h"
28 #include "gettext.h"
29 #include "intl.h"
30 #include "language.h"
31 #include "lyxrc.h"
32 #include "lyxrow.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "ParagraphParameters.h"
36 #include "undo.h"
37 #include "vspace.h"
38
39 #include "frontends/Dialogs.h"
40 #include "frontends/LyXView.h"
41
42 #include "insets/insetcommand.h"
43 #include "insets/insetnewline.h"
44 #include "insets/insetspecialchar.h"
45 #include "insets/insettext.h"
46
47 #include "support/lstrings.h"
48 #include "support/tostr.h"
49 #include "support/std_sstream.h"
50
51 #include "mathed/formulabase.h"
52
53 #include <clocale>
54
55 using bv_funcs::replaceSelection;
56
57 using lyx::pos_type;
58
59 using lyx::support::isStrUnsignedInt;
60 using lyx::support::strToUnsignedInt;
61
62 using std::endl;
63 using std::find;
64 using std::string;
65 using std::istringstream;
66 using std::vector;
67
68
69 extern string current_layout;
70 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
71
72 // the selection possible is needed, that only motion events are
73 // used, where the bottom press event was on the drawing area too
74 bool selection_possible = false;
75
76
77 namespace {
78
79         // globals...
80         LyXFont freefont(LyXFont::ALL_IGNORE);
81         bool toggleall = false;
82
83
84         void toggleAndShow(BufferView * bv, LyXText * text,
85                 LyXFont const & font, bool toggleall = true)
86         {
87                 if (!bv->available())
88                         return;
89
90                 text->toggleFree(font, toggleall);
91                 bv->update();
92
93                 if (font.language() != ignore_language ||
94                                 font.number() != LyXFont::IGNORE) {
95                         LyXCursor & cursor = text->cursor;
96                         Paragraph & par = *text->cursorPar();
97                         text->bidi.computeTables(par, *bv->buffer(),
98                                 *par.getRow(cursor.pos()));
99                         if (cursor.boundary() !=
100                                         text->bidi.isBoundary(*bv->buffer(), par,
101                                                         cursor.pos(),
102                                                         text->real_current_font))
103                                 text->setCursor(cursor.par(), cursor.pos(),
104                                                 false, !cursor.boundary());
105                 }
106         }
107
108
109         /// Apply the contents of freefont at the current cursor location.
110         void apply_freefont(BufferView * bv, LyXText * text)
111         {
112                 toggleAndShow(bv, text, freefont, toggleall);
113                 bv->owner()->view_state_changed();
114                 bv->owner()->message(_("Character set"));
115         }
116
117
118         /** Set the freefont using the contents of \param data dispatched from
119          *  the frontends and apply it at the current cursor location.
120          */
121         void update_and_apply_freefont(BufferView * bv, LyXText * text,
122                 string const & data)
123         {
124                 LyXFont font;
125                 bool toggle;
126                 if (bv_funcs::string2font(data, font, toggle)) {
127                         freefont = font;
128                         toggleall = toggle;
129                         apply_freefont(bv, text);
130                 }
131         }
132
133
134         void emph(BufferView * bv, LyXText * text)
135         {
136                 LyXFont font(LyXFont::ALL_IGNORE);
137                 font.setEmph(LyXFont::TOGGLE);
138                 toggleAndShow(bv, text, font);
139         }
140
141
142         void bold(BufferView * bv, LyXText * text)
143         {
144                 LyXFont font(LyXFont::ALL_IGNORE);
145                 font.setSeries(LyXFont::BOLD_SERIES);
146                 toggleAndShow(bv, text, font);
147         }
148
149
150         void noun(BufferView * bv, LyXText * text)
151         {
152                 LyXFont font(LyXFont::ALL_IGNORE);
153                 font.setNoun(LyXFont::TOGGLE);
154                 toggleAndShow(bv, text, font);
155         }
156
157
158         void lang(BufferView * bv, string const & l, LyXText * text)
159         {
160                 Language const * lang = languages.getLanguage(l);
161                 if (!lang)
162                         return;
163
164                 LyXFont font(LyXFont::ALL_IGNORE);
165                 font.setLanguage(lang);
166                 toggleAndShow(bv, text, font);
167         }
168
169
170         void code(BufferView * bv, LyXText * text)
171         {
172                 LyXFont font(LyXFont::ALL_IGNORE);
173                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
174                 toggleAndShow(bv, text, font);
175         }
176
177
178         void sans(BufferView * bv, LyXText * text)
179         {
180                 LyXFont font(LyXFont::ALL_IGNORE);
181                 font.setFamily(LyXFont::SANS_FAMILY);
182                 toggleAndShow(bv, text, font);
183         }
184
185
186         void roman(BufferView * bv, LyXText * text)
187         {
188                 LyXFont font(LyXFont::ALL_IGNORE);
189                 font.setFamily(LyXFont::ROMAN_FAMILY);
190                 toggleAndShow(bv, text, font);
191         }
192
193
194         void styleReset(BufferView * bv, LyXText * text)
195         {
196                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
197                 toggleAndShow(bv, text, font);
198         }
199
200
201         void underline(BufferView * bv, LyXText * text)
202         {
203                 LyXFont font(LyXFont::ALL_IGNORE);
204                 font.setUnderbar(LyXFont::TOGGLE);
205                 toggleAndShow(bv, text, font);
206         }
207
208
209         void fontSize(BufferView * bv, string const & size, LyXText * text)
210         {
211                 LyXFont font(LyXFont::ALL_IGNORE);
212                 font.setLyXSize(size);
213                 toggleAndShow(bv, text, font);
214         }
215
216
217         void moveCursor(BufferView * bv, bool selecting)
218         {
219                 LyXText * lt = bv->getLyXText();
220
221 //              if (!lt->selection.set())
222 //                      lt->selection.cursor = lt->cursor;
223
224                 if (selecting || lt->selection.mark())
225                         lt->setSelection();
226
227                 if (!lt->selection.set())
228                         bv->haveSelection(false);
229                 bv->switchKeyMap();
230         }
231
232
233         void finishChange(BufferView * bv, bool selecting = false)
234         {
235                 finishUndo();
236                 moveCursor(bv, selecting);
237                 bv->owner()->view_state_changed();
238         }
239
240 } // anon namespace
241
242
243 namespace bv_funcs {
244
245 string const freefont2string()
246 {
247         string data;
248         if (font2string(freefont, toggleall, data))
249                 return data;
250         return string();
251 }
252
253 }
254
255
256
257 InsetOld * LyXText::checkInsetHit(int x, int y)
258 {
259         ParagraphList::iterator pit;
260         ParagraphList::iterator end;
261
262         getParsInRange(ownerParagraphs(),
263                        bv()->top_y() - yo_,
264                        bv()->top_y() - yo_ + bv()->workHeight(),
265                        pit, end);
266
267         lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
268         for ( ; pit != end; ++pit) {
269                 InsetList::iterator iit = pit->insetlist.begin();
270                 InsetList::iterator iend = pit->insetlist.end();
271                 for ( ; iit != iend; ++iit) {
272                         InsetOld * inset = iit->inset;
273                         //lyxerr << "examining inset " << inset
274                         //      << " xy: " << inset->x() << "/" << inset->y()
275                         //      << " x: " << inset->x() << "..." << inset->x() + inset->width()
276                         //      << " y: " << inset->y() - inset->ascent() << "..."
277                         //      << inset->y() + inset->descent()
278                         //      << endl;
279                         if (x >= inset->x()
280                             && x <= inset->x() + inset->width()
281                             && y >= inset->y() - inset->ascent()
282                             && y <= inset->y() + inset->descent())
283                         {
284                                 lyxerr << "Hit inset: " << inset << endl;
285                                 return inset;
286                         }
287                 }
288         }
289         lyxerr << "No inset hit. " << endl;
290         return 0;
291 }
292
293
294 bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
295                             string const & contents)
296 {
297         ParagraphList::iterator end = ownerParagraphs().end();
298         ParagraphList::iterator pit = cursorPar();
299         pos_type pos = cursor.pos();
300
301         InsetOld * inset;
302         do {
303                 if (pos + 1 < pit->size()) {
304                         ++pos;
305                 } else  {
306                         ++pit;
307                         pos = 0;
308                 }
309
310         } while (pit != end &&
311                  !(pit->isInset(pos) &&
312                    (inset = pit->getInset(pos)) != 0 &&
313                    find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
314                    (contents.empty() ||
315                     static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
316                     == contents)));
317
318         if (pit == end)
319                 return false;
320
321         setCursor(parOffset(pit), pos, false);
322         return true;
323 }
324
325
326 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
327                         bool same_content)
328 {
329         clearSelection();
330
331         string contents;
332         if (same_content && cursor.pos() < cursorPar()->size()
333             && cursorPar()->isInset(cursor.pos())) {
334                 InsetOld const * inset = cursorPar()->getInset(cursor.pos());
335                 if (find(codes.begin(), codes.end(), inset->lyxCode())
336                     != codes.end())
337                         contents = static_cast<InsetCommand const *>(inset)->getContents();
338         }
339
340         if (!gotoNextInset(codes, contents)) {
341                 if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
342                         LyXCursor tmp = cursor;
343                         cursor.par(0);
344                         cursor.pos(0);
345                         if (!gotoNextInset(codes, contents)) {
346                                 cursor = tmp;
347                                 bv()->owner()->message(_("No more insets"));
348                         }
349                 } else {
350                         bv()->owner()->message(_("No more insets"));
351                 }
352         }
353         bv()->update();
354         selection.cursor = cursor;
355 }
356
357
358 void LyXText::gotoInset(InsetOld::Code code, bool same_content)
359 {
360         gotoInset(vector<InsetOld::Code>(1, code), same_content);
361 }
362
363
364 void LyXText::cursorPrevious()
365 {
366
367         RowList::iterator crit = cursorRow();
368
369         int x = bv()->x_target() - xo_;
370         int y = bv()->top_y() - yo_;
371         setCursorFromCoordinates(x, y);
372
373         if (crit == cursorRow()) {
374                 // we have a row which is taller than the workarea. The
375                 // simplest solution is to move to the previous row instead.
376                 cursorUp(true);
377         }
378
379         bv()->updateScrollbar();
380         finishUndo();
381 }
382
383
384 void LyXText::cursorNext()
385 {
386         RowList::iterator crit = cursorRow();
387
388         int x = bv()->x_target() - xo_;
389         int y = bv()->top_y() + bv()->workHeight() - yo_;
390         setCursorFromCoordinates(x, y);
391
392         if (crit == cursorRow()) {
393                 // we have a row which is taller than the workarea. The
394                 // simplest solution is to move to the next row instead.
395                 cursorDown(true);
396         }
397
398         bv()->updateScrollbar();
399         finishUndo();
400 }
401
402
403 namespace {
404
405 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
406 {
407         bv->update();
408         InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
409         replaceSelection(lt);
410         if (!bv->insertInset(new_inset))
411                 delete new_inset;
412         else
413                 bv->update();
414 }
415
416
417 void doInsertInset(LyXText * lt, FuncRequest const & cmd,
418                    bool edit, bool pastesel)
419 {
420         InsetOld * inset = createInset(cmd);
421         BufferView * bv = cmd.view();
422
423         if (inset) {
424                 bool gotsel = false;
425                 if (lt->selection.set()) {
426                         bv->owner()->dispatch(FuncRequest(LFUN_CUT));
427                         gotsel = true;
428                 }
429                 if (bv->insertInset(inset)) {
430                         if (edit)
431                                 inset->edit(bv, true);
432                         if (gotsel && pastesel)
433                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
434                 } else
435                         delete inset;
436         }
437 }
438
439 } // anon namespace
440
441
442 void LyXText::number()
443 {
444         LyXFont font(LyXFont::ALL_IGNORE);
445         font.setNumber(LyXFont::TOGGLE);
446         toggleAndShow(bv(), this, font);
447 }
448
449
450 bool LyXText::rtl() const
451 {
452         return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
453 }
454
455
456 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
457 {
458         //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
459         lyxerr << "LyXText::dispatch: cmd: " << cmd << endl;
460
461         BufferView * bv = cmd.view();
462
463         switch (cmd.action) {
464
465         case LFUN_APPENDIX: {
466                 ParagraphList::iterator pit = cursorPar();
467                 bool start = !pit->params().startOfAppendix();
468
469                 // ensure that we have only one start_of_appendix in this document
470                 ParagraphList::iterator tmp = ownerParagraphs().begin();
471                 ParagraphList::iterator end = ownerParagraphs().end();
472
473                 for (; tmp != end; ++tmp) {
474                         if (tmp->params().startOfAppendix()) {
475                                 recUndo(parOffset(tmp));
476                                 tmp->params().startOfAppendix(false);
477                                 redoParagraph(tmp);
478                                 break;
479                         }
480                 }
481
482                 recUndo(parOffset(pit));
483                 pit->params().startOfAppendix(start);
484
485                 // we can set the refreshing parameters now
486                 updateCounters();
487                 redoParagraph(cursorPar());
488                 setCursor(cursorPar(), cursor.pos());
489                 bv->update();
490                 break;
491         }
492
493         case LFUN_DELETE_WORD_FORWARD:
494                 clearSelection();
495                 deleteWordForward();
496                 finishChange(bv);
497                 break;
498
499         case LFUN_DELETE_WORD_BACKWARD:
500                 clearSelection();
501                 deleteWordBackward();
502                 finishChange(bv);
503                 break;
504
505         case LFUN_DELETE_LINE_FORWARD:
506                 clearSelection();
507                 deleteLineForward();
508                 finishChange(bv);
509                 break;
510
511         case LFUN_WORDRIGHT:
512                 if (!selection.mark())
513                         clearSelection();
514                 if (rtl())
515                         cursorLeftOneWord();
516                 else
517                         cursorRightOneWord();
518                 finishChange(bv);
519                 break;
520
521         case LFUN_WORDLEFT:
522                 if (!selection.mark())
523                         clearSelection();
524                 if (rtl())
525                         cursorRightOneWord();
526                 else
527                         cursorLeftOneWord();
528                 finishChange(bv);
529                 break;
530
531         case LFUN_BEGINNINGBUF:
532                 if (!selection.mark())
533                         clearSelection();
534                 cursorTop();
535                 finishChange(bv);
536                 break;
537
538         case LFUN_ENDBUF:
539                 if (selection.mark())
540                         clearSelection();
541                 cursorBottom();
542                 finishChange(bv);
543                 break;
544
545         case LFUN_RIGHTSEL:
546                 if (!selection.set())
547                         selection.cursor = cursor;
548                 if (rtl())
549                         cursorLeft(bv);
550                 else
551                         cursorRight(bv);
552                 finishChange(bv, true);
553                 break;
554
555         case LFUN_LEFTSEL:
556                 if (!selection.set())
557                         selection.cursor = cursor;
558                 if (rtl())
559                         cursorRight(bv);
560                 else
561                         cursorLeft(bv);
562                 finishChange(bv, true);
563                 break;
564
565         case LFUN_UPSEL:
566                 if (!selection.set())
567                         selection.cursor = cursor;
568                 cursorUp(true);
569                 finishChange(bv, true);
570                 break;
571
572         case LFUN_DOWNSEL:
573                 if (!selection.set())
574                         selection.cursor = cursor;
575                 cursorDown(true);
576                 finishChange(bv, true);
577                 break;
578
579         case LFUN_UP_PARAGRAPHSEL:
580                 if (!selection.set())
581                         selection.cursor = cursor;
582                 cursorUpParagraph();
583                 finishChange(bv, true);
584                 break;
585
586         case LFUN_DOWN_PARAGRAPHSEL:
587                 if (!selection.set())
588                         selection.cursor = cursor;
589                 cursorDownParagraph();
590                 finishChange(bv, true);
591                 break;
592
593         case LFUN_PRIORSEL:
594                 if (!selection.set())
595                         selection.cursor = cursor;
596                 cursorPrevious();
597                 finishChange(bv, true);
598                 break;
599
600         case LFUN_NEXTSEL:
601                 if (!selection.set())
602                         selection.cursor = cursor;
603                 cursorNext();
604                 finishChange(bv, true);
605                 break;
606
607         case LFUN_HOMESEL:
608                 if (!selection.set())
609                         selection.cursor = cursor;
610                 cursorHome();
611                 finishChange(bv, true);
612                 break;
613
614         case LFUN_ENDSEL:
615                 if (!selection.set())
616                         selection.cursor = cursor;
617                 cursorEnd();
618                 finishChange(bv, true);
619                 break;
620
621         case LFUN_WORDRIGHTSEL:
622                 if (rtl())
623                         cursorLeftOneWord();
624                 else
625                         cursorRightOneWord();
626                 finishChange(bv, true);
627                 break;
628
629         case LFUN_WORDLEFTSEL:
630                 if (rtl())
631                         cursorRightOneWord();
632                 else
633                         cursorLeftOneWord();
634                 finishChange(bv, true);
635                 break;
636
637         case LFUN_WORDSEL: {
638                 LyXCursor cur1 = cursor;
639                 LyXCursor cur2;
640                 getWord(cur1, cur2, lyx::WHOLE_WORD);
641                 setCursor(cur1.par(), cur1.pos());
642                 clearSelection();
643                 setCursor(cur2.par(), cur2.pos());
644                 finishChange(bv, true);
645                 break;
646         }
647
648         case LFUN_RIGHT:
649                 finishChange(bv);
650                 return moveRight();
651
652         case LFUN_LEFT:
653                 finishChange(bv);
654                 return moveLeft();
655
656         case LFUN_UP:
657                 finishChange(bv);
658                 return moveUp();
659
660         case LFUN_DOWN:
661                 finishChange(bv);
662                 return moveDown();
663
664         case LFUN_UP_PARAGRAPH:
665                 if (!selection.mark())
666                         clearSelection();
667                 cursorUpParagraph();
668                 finishChange(bv);
669                 break;
670
671         case LFUN_DOWN_PARAGRAPH:
672                 if (!selection.mark())
673                         clearSelection();
674                 cursorDownParagraph();
675                 finishChange(bv, false);
676                 break;
677
678         case LFUN_PRIOR:
679                 if (!selection.mark())
680                         clearSelection();
681                 finishChange(bv, false);
682                 if (cursorPar() == firstPar() && cursorRow() == firstRow())
683                         return DispatchResult(false, FINISHED_UP);
684                 cursorPrevious();
685                 break;
686
687         case LFUN_NEXT:
688                 if (!selection.mark())
689                         clearSelection();
690                 finishChange(bv, false);
691                 if (cursorPar() == lastPar() && cursorRow() == lastRow())
692                         return DispatchResult(false, FINISHED_DOWN);
693                 cursorNext();
694                 break;
695
696         case LFUN_HOME:
697                 if (!selection.mark())
698                         clearSelection();
699                 cursorHome();
700                 finishChange(bv, false);
701                 break;
702
703         case LFUN_END:
704                 if (!selection.mark())
705                         clearSelection();
706                 cursorEnd();
707                 finishChange(bv, false);
708                 break;
709
710         case LFUN_BREAKLINE: {
711                 lyx::pos_type body = cursorPar()->beginOfBody();
712
713                 // Not allowed by LaTeX (labels or empty par)
714                 if (cursor.pos() <= body)
715                         break;
716
717                 replaceSelection(bv->getLyXText());
718                 insertInset(new InsetNewline);
719                 setCursor(cursorPar(), cursor.pos());
720                 moveCursor(bv, false);
721                 break;
722         }
723
724         case LFUN_DELETE:
725                 if (!selection.set()) {
726                         Delete();
727                         selection.cursor = cursor;
728                         // It is possible to make it a lot faster still
729                         // just comment out the line below...
730                 } else {
731                         cutSelection(true, false);
732                 }
733                 moveCursor(bv, false);
734                 bv->owner()->view_state_changed();
735                 break;
736
737         case LFUN_DELETE_SKIP:
738                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
739                 if (!selection.set()) {
740                         if (cursor.pos() == cursorPar()->size()) {
741                                 cursorRight(bv);
742                                 ParagraphParameters & params = cursorPar()->params();
743                                 if (cursor.pos() == 0
744                                     && !(params.spaceTop() == VSpace (VSpace::NONE))) {
745                                         setParagraph(
746                                                  VSpace(VSpace::NONE),
747                                                  params.spaceBottom(),
748                                                  params.spacing(),
749                                                  params.align(),
750                                                  params.labelWidthString(), 0);
751                                         cursorLeft(bv);
752                                 } else {
753                                         cursorLeft(bv);
754                                         Delete();
755                                         selection.cursor = cursor;
756                                 }
757                         } else {
758                                 Delete();
759                                 selection.cursor = cursor;
760                         }
761                 } else {
762                         cutSelection(true, false);
763                 }
764                 bv->update();
765                 break;
766
767
768         case LFUN_BACKSPACE:
769                 if (!selection.set()) {
770                         if (bv->owner()->getIntl().getTransManager().backspace()) {
771                                 backspace();
772                                 selection.cursor = cursor;
773                                 // It is possible to make it a lot faster still
774                                 // just comment out the line below...
775                         }
776                 } else {
777                         cutSelection(true, false);
778                 }
779                 bv->owner()->view_state_changed();
780                 bv->switchKeyMap();
781                 bv->update();
782                 break;
783
784         case LFUN_BACKSPACE_SKIP:
785                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
786                 if (!selection.set()) {
787                         ParagraphParameters & params = cursorPar()->params();
788                         if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
789                                 setParagraph(
790                                          VSpace(VSpace::NONE),
791                                    params.spaceBottom(),
792                                          params.spacing(),
793                                          params.align(),
794                                          params.labelWidthString(), 0);
795                         } else {
796                                 LyXCursor cur = cursor;
797                                 backspace();
798                                 selection.cursor = cur;
799                         }
800                 } else {
801                         cutSelection(true, false);
802                 }
803                 bv->update();
804                 break;
805
806         case LFUN_BREAKPARAGRAPH:
807                 replaceSelection(bv->getLyXText());
808                 breakParagraph(bv->buffer()->paragraphs(), 0);
809                 bv->update();
810                 selection.cursor = cursor;
811                 bv->switchKeyMap();
812                 bv->owner()->view_state_changed();
813                 break;
814
815         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
816                 replaceSelection(bv->getLyXText());
817                 breakParagraph(bv->buffer()->paragraphs(), 1);
818                 bv->update();
819                 selection.cursor = cursor;
820                 bv->switchKeyMap();
821                 bv->owner()->view_state_changed();
822                 break;
823
824         case LFUN_BREAKPARAGRAPH_SKIP: {
825                 // When at the beginning of a paragraph, remove
826                 // indentation and add a "defskip" at the top.
827                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
828                 LyXCursor cur = cursor;
829                 replaceSelection(bv->getLyXText());
830                 if (cur.pos() == 0) {
831                         ParagraphParameters & params = getPar(cur)->params();
832                         if (params.spaceTop() == VSpace(VSpace::NONE)) {
833                                 setParagraph(
834                                          VSpace(VSpace::DEFSKIP), params.spaceBottom(),
835                                          params.spacing(),
836                                          params.align(),
837                                          params.labelWidthString(), 1);
838                         }
839                 }
840                 else {
841                         breakParagraph(bv->buffer()->paragraphs(), 0);
842                 }
843                 bv->update();
844                 selection.cursor = cur;
845                 bv->switchKeyMap();
846                 bv->owner()->view_state_changed();
847                 break;
848         }
849
850         case LFUN_PARAGRAPH_SPACING: {
851                 ParagraphList::iterator pit = cursorPar();
852                 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
853                 float cur_value = 1.0;
854                 if (cur_spacing == Spacing::Other)
855                         cur_value = pit->params().spacing().getValue();
856
857                 istringstream is(cmd.argument);
858                 string tmp;
859                 is >> tmp;
860                 Spacing::Space new_spacing = cur_spacing;
861                 float new_value = cur_value;
862                 if (tmp.empty()) {
863                         lyxerr << "Missing argument to `paragraph-spacing'"
864                                << endl;
865                 } else if (tmp == "single") {
866                         new_spacing = Spacing::Single;
867                 } else if (tmp == "onehalf") {
868                         new_spacing = Spacing::Onehalf;
869                 } else if (tmp == "double") {
870                         new_spacing = Spacing::Double;
871                 } else if (tmp == "other") {
872                         new_spacing = Spacing::Other;
873                         float tmpval = 0.0;
874                         is >> tmpval;
875                         lyxerr << "new_value = " << tmpval << endl;
876                         if (tmpval != 0.0)
877                                 new_value = tmpval;
878                 } else if (tmp == "default") {
879                         new_spacing = Spacing::Default;
880                 } else {
881                         lyxerr << _("Unknown spacing argument: ")
882                                << cmd.argument << endl;
883                 }
884                 if (cur_spacing != new_spacing || cur_value != new_value) {
885                         pit->params().spacing(Spacing(new_spacing, new_value));
886                         redoParagraph();
887                         bv->update();
888                 }
889                 break;
890         }
891
892         case LFUN_INSET_APPLY: {
893                 string const name = cmd.getArg(0);
894                 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
895                 if (inset) {
896                         FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
897                         inset->dispatch(fr);
898                 } else {
899                         FuncRequest fr(bv, LFUN_INSET_INSERT, cmd.argument);
900                         dispatch(fr);
901                 }
902                 break;
903         }
904
905         case LFUN_INSET_INSERT: {
906                 InsetOld * inset = createInset(cmd);
907                 if (!inset || !bv->insertInset(inset))
908                         delete inset;
909                 break;
910                 }
911
912         case LFUN_INSET_SETTINGS:
913                 bv->cursor().innerInset()->showInsetDialog(bv);
914                 break;
915
916         case LFUN_INSET_TOGGLE:
917                 clearSelection();
918                 toggleInset();
919                 bv->update();
920                 bv->switchKeyMap();
921                 break;
922
923         case LFUN_SPACE_INSERT:
924                 if (cursorPar()->layout()->free_spacing)
925                         insertChar(' ');
926                 else
927                         doInsertInset(this, cmd, false, false);
928                 moveCursor(bv, false);
929                 break;
930
931         case LFUN_HYPHENATION:
932                 specialChar(this, bv, InsetSpecialChar::HYPHENATION);
933                 break;
934
935         case LFUN_LIGATURE_BREAK:
936                 specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK);
937                 break;
938
939         case LFUN_LDOTS:
940                 specialChar(this, bv, InsetSpecialChar::LDOTS);
941                 break;
942
943         case LFUN_END_OF_SENTENCE:
944                 specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE);
945                 break;
946
947         case LFUN_MENU_SEPARATOR:
948                 specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
949                 break;
950
951         case LFUN_MARK_OFF:
952                 clearSelection();
953                 bv->update();
954                 selection.cursor = cursor;
955                 cmd.message(N_("Mark off"));
956                 break;
957
958         case LFUN_MARK_ON:
959                 clearSelection();
960                 selection.mark(true);
961                 bv->update();
962                 selection.cursor = cursor;
963                 cmd.message(N_("Mark on"));
964                 break;
965
966         case LFUN_SETMARK:
967                 clearSelection();
968                 if (selection.mark()) {
969                         cmd.message(N_("Mark removed"));
970                 } else {
971                         selection.mark(true);
972                         cmd.message(N_("Mark set"));
973                 }
974                 selection.cursor = cursor;
975                 bv->update();
976                 break;
977
978         case LFUN_UPCASE_WORD:
979                 changeCase(LyXText::text_uppercase);
980                 bv->update();
981                 break;
982
983         case LFUN_LOWCASE_WORD:
984                 changeCase(LyXText::text_lowercase);
985                 bv->update();
986                 break;
987
988         case LFUN_CAPITALIZE_WORD:
989                 changeCase(LyXText::text_capitalization);
990                 bv->update();
991                 break;
992
993         case LFUN_TRANSPOSE_CHARS:
994                 recUndo(cursor.par());
995                 redoParagraph();
996                 bv->update();
997                 break;
998
999         case LFUN_PASTE:
1000                 cmd.message(_("Paste"));
1001                 replaceSelection(bv->getLyXText());
1002 #warning FIXME Check if the arg is in the domain of available selections.
1003                 if (isStrUnsignedInt(cmd.argument))
1004                         pasteSelection(strToUnsignedInt(cmd.argument));
1005                 else
1006                         pasteSelection(0);
1007                 clearSelection(); // bug 393
1008                 bv->update();
1009                 bv->switchKeyMap();
1010                 finishUndo();
1011                 break;
1012
1013         case LFUN_CUT:
1014                 cutSelection(true, true);
1015                 cmd.message(_("Cut"));
1016                 bv->update();
1017                 break;
1018
1019         case LFUN_COPY:
1020                 copySelection();
1021                 cmd.message(_("Copy"));
1022                 break;
1023
1024         case LFUN_BEGINNINGBUFSEL:
1025                 if (inset_owner)
1026                         return DispatchResult(false);
1027                 cursorTop();
1028                 finishChange(bv, true);
1029                 break;
1030
1031         case LFUN_ENDBUFSEL:
1032                 if (inset_owner)
1033                         return DispatchResult(false);
1034                 cursorBottom();
1035                 finishChange(bv, true);
1036                 break;
1037
1038         case LFUN_GETXY:
1039                 cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y()));
1040                 break;
1041
1042         case LFUN_SETXY: {
1043                 int x = 0;
1044                 int y = 0;
1045                 istringstream is(cmd.argument);
1046                 is >> x >> y;
1047                 if (!is)
1048                         lyxerr << "SETXY: Could not parse coordinates in '"
1049                                << cmd.argument << std::endl;
1050                 else
1051                         setCursorFromCoordinates(x, y);
1052                 break;
1053         }
1054
1055         case LFUN_GETFONT:
1056                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
1057                         cmd.message("E");
1058                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
1059                         cmd.message("N");
1060                 else
1061                         cmd.message("0");
1062                 break;
1063
1064         case LFUN_GETLAYOUT:
1065                 cmd.message(tostr(cursorPar()->layout()));
1066                 break;
1067
1068         case LFUN_LAYOUT: {
1069                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
1070                   << cmd.argument << endl;
1071
1072                 // This is not the good solution to the empty argument
1073                 // problem, but it will hopefully suffice for 1.2.0.
1074                 // The correct solution would be to augument the
1075                 // function list/array with information about what
1076                 // functions needs arguments and their type.
1077                 if (cmd.argument.empty()) {
1078                         cmd.errorMessage(_("LyX function 'layout' needs an argument."));
1079                         break;
1080                 }
1081
1082                 // Derive layout number from given argument (string)
1083                 // and current buffer's textclass (number)
1084                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1085                 bool hasLayout = tclass.hasLayout(cmd.argument);
1086                 string layout = cmd.argument;
1087
1088                 // If the entry is obsolete, use the new one instead.
1089                 if (hasLayout) {
1090                         string const & obs = tclass[layout]->obsoleted_by();
1091                         if (!obs.empty())
1092                                 layout = obs;
1093                 }
1094
1095                 if (!hasLayout) {
1096                         cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
1097                                 N_(" not known"));
1098                         break;
1099                 }
1100
1101                 bool change_layout = (current_layout != layout);
1102
1103                 if (!change_layout && selection.set() &&
1104                         selection.start.par() != selection.end.par())
1105                 {
1106                         ParagraphList::iterator spit = getPar(selection.start);
1107                         ParagraphList::iterator epit = boost::next(getPar(selection.end));
1108                         while (spit != epit) {
1109                                 if (spit->layout()->name() != current_layout) {
1110                                         change_layout = true;
1111                                         break;
1112                                 }
1113                                 ++spit;
1114                         }
1115                 }
1116
1117                 if (change_layout) {
1118                         current_layout = layout;
1119                         setLayout(layout);
1120                         bv->owner()->setLayout(layout);
1121                         bv->update();
1122                         bv->switchKeyMap();
1123                 }
1124                 break;
1125         }
1126
1127         case LFUN_PASTESELECTION: {
1128                 // this was originally a bv->text->clearSelection(), i.e
1129                 // the outermost LyXText!
1130                 clearSelection();
1131                 string const clip = bv->getClipboard();
1132                 if (!clip.empty()) {
1133                         if (cmd.argument == "paragraph")
1134                                 insertStringAsParagraphs(clip);
1135                         else
1136                                 insertStringAsLines(clip);
1137                         bv->update();
1138                 }
1139                 break;
1140         }
1141
1142         case LFUN_GOTOERROR:
1143                 gotoInset(InsetOld::ERROR_CODE, false);
1144                 break;
1145
1146         case LFUN_GOTONOTE:
1147                 gotoInset(InsetOld::NOTE_CODE, false);
1148                 break;
1149
1150         case LFUN_REFERENCE_GOTO: {
1151                 vector<InsetOld::Code> tmp;
1152                 tmp.push_back(InsetOld::LABEL_CODE);
1153                 tmp.push_back(InsetOld::REF_CODE);
1154                 gotoInset(tmp, true);
1155                 break;
1156         }
1157
1158         case LFUN_QUOTE: {
1159                 replaceSelection(bv->getLyXText());
1160                 ParagraphList::iterator pit = cursorPar();
1161                 lyx::pos_type pos = cursor.pos();
1162                 char c;
1163                 if (!pos)
1164                         c = ' ';
1165                 else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
1166                         c = ' ';
1167                 else
1168                         c = pit->getChar(pos - 1);
1169
1170                 LyXLayout_ptr const & style = pit->layout();
1171
1172                 BufferParams const & bufparams = bv->buffer()->params();
1173                 if (style->pass_thru ||
1174                     pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
1175                     !bv->insertInset(new InsetQuotes(c, bufparams)))
1176                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1177                 break;
1178         }
1179
1180         case LFUN_DATE_INSERT: {
1181                 replaceSelection(bv->getLyXText());
1182                 time_t now_time_t = time(NULL);
1183                 struct tm * now_tm = localtime(&now_time_t);
1184                 setlocale(LC_TIME, "");
1185                 string arg;
1186                 if (!cmd.argument.empty())
1187                         arg = cmd.argument;
1188                 else
1189                         arg = lyxrc.date_insert_format;
1190                 char datetmp[32];
1191                 int const datetmp_len =
1192                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1193
1194                 for (int i = 0; i < datetmp_len; i++)
1195                         insertChar(datetmp[i]);
1196
1197                 selection.cursor = cursor;
1198                 moveCursor(bv, false);
1199                 break;
1200         }
1201
1202         case LFUN_MOUSE_TRIPLE:
1203                 if (!bv->buffer())
1204                         break;
1205                 if (cmd.button() == mouse_button::button1) {
1206                         selection_possible = true;
1207                         cursorHome();
1208                         selection.cursor = cursor;
1209                         cursorEnd();
1210                         setSelection();
1211                         bv->haveSelection(selection.set());
1212                 }
1213                 break;
1214
1215         case LFUN_MOUSE_DOUBLE:
1216                 if (!bv->buffer())
1217                         break;
1218                 if (cmd.button() == mouse_button::button1) {
1219                         selection_possible = true;
1220                         selectWord(lyx::WHOLE_WORD_STRICT);
1221                         bv->haveSelection(selection.set());
1222                 }
1223                 break;
1224
1225         case LFUN_MOUSE_MOTION: {
1226                 // Only use motion with button 1
1227                 //if (ev.button() != mouse_button::button1)
1228                 //      return false;
1229
1230                 if (!bv->buffer())
1231                         break;
1232                 // The test for not selection possible is needed, that
1233                 // only motion events are used, where the bottom press
1234                 // event was on the drawing area too
1235                 if (!selection_possible) {
1236                         lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1237                                 "Dispatch: no selection possible\n";
1238                         break;
1239                 }
1240                 RowList::iterator cursorrow = cursorRow();
1241
1242                 setCursorFromCoordinates(cmd.x, cmd.y);
1243
1244                 // This is to allow jumping over large insets
1245                 // FIXME: shouldn't be top-text-specific
1246                 if (cursorrow == cursorRow() && !in_inset_) {
1247                         if (cmd.y - bv->top_y() >= bv->workHeight())
1248                                 cursorDown(true);
1249                         else if (cmd.y - bv->top_y() < 0)
1250                                 cursorUp(true);
1251                 }
1252                 setSelection();
1253                 break;
1254         }
1255
1256         // Single-click on work area
1257         case LFUN_MOUSE_PRESS: {
1258                 if (!bv->buffer())
1259                         break;
1260
1261                 // ok ok, this is a hack (for xforms)
1262                 // We shouldn't go further down as we really should only do the
1263                 // scrolling and be done with this. Otherwise we may open some
1264                 // dialogs (Jug 20020424).
1265                 if (cmd.button() == mouse_button::button4) {
1266                         bv->scroll(-lyxrc.wheel_jump);
1267                         break;
1268                 }
1269                 if (cmd.button() == mouse_button::button5) {
1270                         bv->scroll(lyxrc.wheel_jump);
1271                         break;
1272                 }
1273
1274                 // Middle button press pastes if we have a selection
1275                 // We do this here as if the selection was inside an inset
1276                 // it could get cleared on the unlocking of the inset so
1277                 // we have to check this first
1278                 bool paste_internally = false;
1279                 if (cmd.button() == mouse_button::button2 && selection.set()) {
1280                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1281                         paste_internally = true;
1282                 }
1283
1284                 selection_possible = true;
1285
1286                 // Clear the selection
1287                 clearSelection();
1288
1289                 // Right click on a footnote flag opens float menu
1290                 if (cmd.button() == mouse_button::button3) {
1291                         selection_possible = false;
1292                         break;
1293                 }
1294
1295                 setCursorFromCoordinates(cmd.x, cmd.y);
1296                 selection.cursor = cursor;
1297                 finishUndo();
1298                 bv->x_target(cursor.x() + xo_);
1299
1300                 if (bv->fitCursor())
1301                         selection_possible = false;
1302
1303                 // Insert primary selection with middle mouse
1304                 // if there is a local selection in the current buffer,
1305                 // insert this
1306                 if (cmd.button() == mouse_button::button2) {
1307                         if (paste_internally)
1308                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1309                         else
1310                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1311                         selection_possible = false;
1312                 }
1313                 break;
1314         }
1315
1316         case LFUN_MOUSE_RELEASE: {
1317                 if (!bv->buffer())
1318                         break;
1319
1320                 // do nothing if we used the mouse wheel
1321                 if (cmd.button() == mouse_button::button4
1322                  || cmd.button() == mouse_button::button5)
1323                         return DispatchResult(true, false);
1324
1325                 selection_possible = false;
1326
1327                 if (cmd.button() == mouse_button::button2)
1328                         break;
1329
1330                 // finish selection
1331                 if (cmd.button() == mouse_button::button1)
1332                         bv->haveSelection(selection.set());
1333
1334                 bv->switchKeyMap();
1335                 bv->owner()->view_state_changed();
1336                 bv->owner()->updateMenubar();
1337                 bv->owner()->updateToolbar();
1338                 break;
1339         }
1340
1341         case LFUN_SELFINSERT: {
1342                 if (cmd.argument.empty())
1343                         break;
1344
1345                 // Automatically delete the currently selected
1346                 // text and replace it with what is being
1347                 // typed in now. Depends on lyxrc settings
1348                 // "auto_region_delete", which defaults to
1349                 // true (on).
1350
1351                 if (lyxrc.auto_region_delete) {
1352                         if (selection.set())
1353                                 cutSelection(false, false);
1354                         bv->haveSelection(false);
1355                 }
1356
1357                 clearSelection();
1358                 LyXFont const old_font = real_current_font;
1359
1360                 string::const_iterator cit = cmd.argument.begin();
1361                 string::const_iterator end = cmd.argument.end();
1362                 for (; cit != end; ++cit)
1363                         bv->owner()->getIntl().getTransManager().
1364                                 TranslateAndInsert(*cit, this);
1365
1366                 selection.cursor = cursor;
1367                 moveCursor(bv, false);
1368
1369                 // real_current_font.number can change so we need to
1370                 // update the minibuffer
1371                 if (old_font != real_current_font)
1372                         bv->owner()->view_state_changed();
1373                 bv->updateScrollbar();
1374                 break;
1375         }
1376
1377         case LFUN_URL: {
1378                 InsetCommandParams p("url");
1379                 string const data = InsetCommandMailer::params2string("url", p);
1380                 bv->owner()->getDialogs().show("url", data, 0);
1381                 break;
1382         }
1383
1384         case LFUN_HTMLURL: {
1385                 InsetCommandParams p("htmlurl");
1386                 string const data = InsetCommandMailer::params2string("url", p);
1387                 bv->owner()->getDialogs().show("url", data, 0);
1388                 break;
1389         }
1390
1391         case LFUN_INSERT_LABEL: {
1392                 InsetCommandParams p("label");
1393                 string const data = InsetCommandMailer::params2string("label", p);
1394                 bv->owner()->getDialogs().show("label", data, 0);
1395                 break;
1396         }
1397
1398
1399 #if 0
1400         case LFUN_INSET_LIST:
1401         case LFUN_INSET_THEOREM:
1402         case LFUN_INSET_CAPTION:
1403 #endif
1404         case LFUN_INSERT_NOTE:
1405         case LFUN_INSERT_CHARSTYLE:
1406         case LFUN_INSERT_BOX:
1407         case LFUN_INSERT_BRANCH:
1408         case LFUN_INSERT_BIBITEM:
1409         case LFUN_INSET_ERT:
1410         case LFUN_INSET_FLOAT:
1411         case LFUN_INSET_FOOTNOTE:
1412         case LFUN_INSET_MARGINAL:
1413         case LFUN_INSET_MINIPAGE:
1414         case LFUN_INSET_OPTARG:
1415         case LFUN_INSET_WIDE_FLOAT:
1416         case LFUN_INSET_WRAP:
1417         case LFUN_TABULAR_INSERT:
1418         case LFUN_ENVIRONMENT_INSERT:
1419                 // Open the inset, and move the current selection
1420                 // inside it.
1421                 doInsertInset(this, cmd, true, true);
1422                 break;
1423
1424         case LFUN_INDEX_INSERT:
1425                 // Just open the inset
1426                 doInsertInset(this, cmd, true, false);
1427                 break;
1428
1429         case LFUN_INDEX_PRINT:
1430         case LFUN_TOC_INSERT:
1431         case LFUN_HFILL:
1432         case LFUN_INSERT_LINE:
1433         case LFUN_INSERT_PAGEBREAK:
1434                 // do nothing fancy
1435                 doInsertInset(this, cmd, false, false);
1436                 break;
1437
1438         case LFUN_DEPTH_MIN:
1439                 clearSelection();
1440                 bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
1441                 bv->update();
1442                 break;
1443
1444         case LFUN_DEPTH_PLUS:
1445                 clearSelection();
1446                 bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
1447                 bv->update();
1448                 break;
1449
1450         case LFUN_MATH_DELIM:
1451         case LFUN_MATH_DISPLAY:
1452         case LFUN_INSERT_MATH:
1453         case LFUN_MATH_LIMITS:
1454         case LFUN_MATH_MACRO:
1455         case LFUN_MATH_MUTATE:
1456         case LFUN_MATH_SPACE:
1457         case LFUN_MATH_IMPORT_SELECTION:
1458         case LFUN_MATH_MODE:
1459         case LFUN_MATH_NONUMBER:
1460         case LFUN_MATH_NUMBER:
1461         case LFUN_MATH_EXTERN:
1462         case LFUN_MATH_SIZE:
1463                 mathDispatch(cmd);
1464                 break;
1465
1466         case LFUN_EMPH:
1467                 emph(bv, this);
1468                 bv->owner()->view_state_changed();
1469                 break;
1470
1471         case LFUN_BOLD:
1472                 bold(bv, this);
1473                 bv->owner()->view_state_changed();
1474                 break;
1475
1476         case LFUN_NOUN:
1477                 noun(bv, this);
1478                 bv->owner()->view_state_changed();
1479                 break;
1480
1481         case LFUN_CODE:
1482                 code(bv, this);
1483                 bv->owner()->view_state_changed();
1484                 break;
1485
1486         case LFUN_SANS:
1487                 sans(bv, this);
1488                 bv->owner()->view_state_changed();
1489                 break;
1490
1491         case LFUN_ROMAN:
1492                 roman(bv, this);
1493                 bv->owner()->view_state_changed();
1494                 break;
1495
1496         case LFUN_DEFAULT:
1497                 styleReset(bv, this);
1498                 bv->owner()->view_state_changed();
1499                 break;
1500
1501         case LFUN_UNDERLINE:
1502                 underline(bv, this);
1503                 bv->owner()->view_state_changed();
1504                 break;
1505
1506         case LFUN_FONT_SIZE:
1507                 fontSize(bv, cmd.argument, this);
1508                 bv->owner()->view_state_changed();
1509                 break;
1510
1511         case LFUN_LANGUAGE:
1512                 lang(bv, cmd.argument, this);
1513                 bv->switchKeyMap();
1514                 bv->owner()->view_state_changed();
1515                 break;
1516
1517         case LFUN_FREEFONT_APPLY:
1518                 apply_freefont(bv, this);
1519                 break;
1520
1521         case LFUN_FREEFONT_UPDATE:
1522                 update_and_apply_freefont(bv, this, cmd.argument);
1523                 break;
1524
1525         case LFUN_FINISHED_LEFT:
1526                 lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
1527                 if (rtl())
1528                         cursorRight(true);
1529                 break;
1530
1531         case LFUN_FINISHED_RIGHT:
1532                 lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
1533                 if (!rtl())
1534                         cursorRight(true);
1535                 break;
1536
1537         case LFUN_FINISHED_UP:
1538                 lyxerr << "swallow LFUN_FINISHED_UP" << endl;
1539                 cursorUp(true);
1540                 break;
1541
1542         case LFUN_FINISHED_DOWN:
1543                 lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
1544                 cursorDown(true);
1545                 break;
1546
1547         default:
1548                 return DispatchResult(false);
1549         }
1550
1551         return DispatchResult(true, true);
1552 }