diff options
author | fvogel <fvogelnew1@free.fr> | 2018-01-28 15:45:45 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2018-01-28 15:45:45 (GMT) |
commit | 45ee94dff4405aa24cdccccbe00b5bab3d549c43 (patch) | |
tree | 1681af046e9449810fcc07d0cd3c83d490dbaf1f | |
parent | dfaf0f6750758e9dce77363c8b09d6fdf5d5afe5 (diff) | |
parent | ce270e3152dc902f3b190091f767f5b9c6673aa4 (diff) | |
download | tk-45ee94dff4405aa24cdccccbe00b5bab3d549c43.zip tk-45ee94dff4405aa24cdccccbe00b5bab3d549c43.tar.gz tk-45ee94dff4405aa24cdccccbe00b5bab3d549c43.tar.bz2 |
Fix [b68710aed6]: Minor fixes to library/text.tcl bindings, and generation of <<Selection>> events. Legacy text widget.
-rw-r--r-- | generic/tkText.c | 65 | ||||
-rw-r--r-- | library/text.tcl | 4 | ||||
-rw-r--r-- | tests/text.test | 108 |
3 files changed, 141 insertions, 36 deletions
diff --git a/generic/tkText.c b/generic/tkText.c index 846f50c..308855f 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -2726,10 +2726,14 @@ InsertChars( } /* - * Invalidate any selection retrievals in progress. + * Invalidate any selection retrievals in progress, and send an event + * that the selection changed if that is the case. */ for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) { + if (TkBTreeCharTagged(indexPtr, tPtr->selTagPtr)) { + TkTextSelectionEvent(tPtr); + } tPtr->abortSelections = 1; } @@ -3069,6 +3073,9 @@ DeleteIndexRange( int *lineAndByteIndex; int resetViewCount; int pixels[2*PIXEL_CLIENTS]; + Tcl_HashSearch search; + Tcl_HashEntry *hPtr; + int i; if (sharedTextPtr == NULL) { sharedTextPtr = textPtr->sharedTextPtr; @@ -3133,42 +3140,36 @@ DeleteIndexRange( } } - if (line1 < line2) { - /* - * We are deleting more than one line. For speed, we remove all tags - * from the range first. If we don't do this, the code below can (when - * there are many tags) grow non-linearly in execution time. - */ - - Tcl_HashSearch search; - Tcl_HashEntry *hPtr; - int i; + /* + * For speed, we remove all tags from the range first. If we don't + * do this, the code below can (when there are many tags) grow + * non-linearly in execution time. + */ - for (i=0, hPtr=Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search); - hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) { - TkTextTag *tagPtr = Tcl_GetHashValue(hPtr); + for (i=0, hPtr=Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search); + hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) { + TkTextTag *tagPtr = Tcl_GetHashValue(hPtr); - TkBTreeTag(&index1, &index2, tagPtr, 0); - } + TkBTreeTag(&index1, &index2, tagPtr, 0); + } - /* - * Special case for the sel tag which is not in the hash table. We - * need to do this once for each peer text widget. - */ + /* + * Special case for the sel tag which is not in the hash table. We + * need to do this once for each peer text widget. + */ - for (tPtr = sharedTextPtr->peers; tPtr != NULL ; - tPtr = tPtr->next) { - if (TkBTreeTag(&index1, &index2, tPtr->selTagPtr, 0)) { - /* - * Send an event that the selection changed. This is - * equivalent to: - * event generate $textWidget <<Selection>> - */ + for (tPtr = sharedTextPtr->peers; tPtr != NULL ; + tPtr = tPtr->next) { + if (TkBTreeTag(&index1, &index2, tPtr->selTagPtr, 0)) { + /* + * Send an event that the selection changed. This is + * equivalent to: + * event generate $textWidget <<Selection>> + */ - TkTextSelectionEvent(textPtr); - tPtr->abortSelections = 1; - } - } + TkTextSelectionEvent(textPtr); + tPtr->abortSelections = 1; + } } /* diff --git a/library/text.tcl b/library/text.tcl index 645776d..468696b 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -1058,13 +1058,13 @@ proc ::tk_textCut w { # make <<Cut>> an atomic operation on the Undo stack, # i.e. separate it from other delete operations on either side set oldSeparator [$w cget -autoseparators] - if {$oldSeparator} { + if {([$w cget -state] eq "normal") && $oldSeparator} { $w edit separator } clipboard clear -displayof $w clipboard append -displayof $w $data $w delete sel.first sel.last - if {$oldSeparator} { + if {([$w cget -state] eq "normal") && $oldSeparator} { $w edit separator } } diff --git a/tests/text.test b/tests/text.test index 07192e8..5b688f1 100644 --- a/tests/text.test +++ b/tests/text.test @@ -6395,9 +6395,9 @@ test text-27.14a {<<Modified>> virtual event - propagation to peers} -body { } -cleanup { destroy .t .tt } -result {4} -test text-27.15 {<<Selection>> virtual event} -body { +test text-27.15 {<<Selection>> virtual event on sel tagging} -body { set ::retval no_selection - pack [text .t -undo 1] + pack [text .t] bind .t <<Selection>> "set ::retval selection_changed" update idletasks .t insert end "nothing special\n" @@ -6407,6 +6407,110 @@ test text-27.15 {<<Selection>> virtual event} -body { } -cleanup { destroy .t } -result {selection_changed} +test text-27.15a {<<Selection>> virtual event on sel removal} -body { + set ::retval no_selection + pack [text .t] + .t insert end "nothing special\n" + .t tag add sel 1.0 1.1 + bind .t <<Selection>> "set ::retval selection_changed" + update idletasks + .t tag remove 1.0 end + update + set ::retval +} -cleanup { + destroy .t +} -result {selection_changed} +test text-27.15b {<<Selection>> virtual event on <<PasteSelection>> inside widget selection} -body { + pack [text .t] + .t insert end "There is a selection in this text widget,\n" + .t insert end "and it will be impacted by the <<PasteSelection>> event received.\n" + .t insert end "Therefore a <<Selection>> event must fire back." + .t tag add sel 1.0 1.28 + bind .t <<Selection>> "set ::retval <<Selection>>_fired" + update + set ::retval no_<<Selection>>_event_fired + event generate .t <<PasteSelection>> -x 15 -y 3 + update + set ::retval +} -cleanup { + destroy .t +} -result {<<Selection>>_fired} +test text-27.15c {No <<Selection>> virtual event on <<PasteSelection>> outside widget selection} -body { + pack [text .t] + .t insert end "There is a selection in this text widget,\n" + .t insert end "but it will not be impacted by the <<PasteSelection>> event received." + .t tag add sel 1.0 1.28 + bind .t <<Selection>> "set ::retval <<Selection>>_fired" + update + set ::retval no_<<Selection>>_event_fired + event generate .t <<PasteSelection>> -x 15 -y 80 + update + set ::retval +} -cleanup { + destroy .t +} -result {no_<<Selection>>_event_fired} +test text-27.15d {<<Selection>> virtual event on <Delete> with cursor inside selection} -body { + pack [text .t] + .t insert end "There is a selection in this text widget,\n" + .t insert end "and it will be impacted by the <Delete> event received.\n" + .t insert end "Therefore a <<Selection>> event must fire back." + .t tag add sel 1.0 1.28 + bind .t <<Selection>> "set ::retval <<Selection>>_fired" + update + set ::retval no_<<Selection>>_event_fired + .t mark set insert 1.15 + focus .t + event generate .t <Delete> + update + set ::retval +} -cleanup { + destroy .t +} -result {<<Selection>>_fired} +test text-27.15e {No <<Selection>> virtual event on <Delete> with cursor outside selection} -body { + pack [text .t] + .t insert end "There is a selection in this text widget,\n" + .t insert end "but it will not be impacted by the <Delete> event received." + .t tag add sel 1.0 1.28 + bind .t <<Selection>> "set ::retval <<Selection>>_fired" + update + set ::retval no_<<Selection>>_event_fired + .t mark set insert 2.15 + focus .t + event generate .t <Delete> + update + set ::retval +} -cleanup { + destroy .t +} -result {no_<<Selection>>_event_fired} +test text-27.15f {<<Selection>> virtual event on <<Cut>> with a widget selection} -body { + pack [text .t] + .t insert end "There is a selection in this text widget,\n" + .t insert end "and it will be impacted by the <<Cut>> event received.\n" + .t insert end "Therefore a <<Selection>> event must fire back." + .t tag add sel 1.0 1.28 + bind .t <<Selection>> "set ::retval <<Selection>>_fired" + update + set ::retval no_<<Selection>>_event_fired + event generate .t <<Cut>> + update + set ::retval +} -cleanup { + destroy .t +} -result {<<Selection>>_fired} +test text-27.15g {No <<Selection>> virtual event on <<Cut>> without widget selection} -body { + pack [text .t] + .t insert end "There is a selection in this text widget,\n" + .t insert end "and it will be impacted by the <<Cut>> event received.\n" + .t insert end "Therefore a <<Selection>> event must fire back." + bind .t <<Selection>> "set ::retval <<Selection>>_fired" + update + set ::retval no_<<Selection>>_event_fired + event generate .t <<Cut>> + update + set ::retval +} -cleanup { + destroy .t +} -result {no_<<Selection>>_event_fired} test text-27.16 {-maxundo configuration option} -body { text .t -undo 1 -autoseparators 1 -maxundo 2 pack .t |