# ACTIVESTATE TEAPOT-PKG BEGIN TM -*- tcl -*- # -- Tcl Module # @@ Meta Begin # Package ntext 0.81 # Meta as::build::date 2015-05-26 # Meta as::origin http://sourceforge.net/projects/tcllib # Meta category Alternative Bindings for the Text Widget Alternative # Meta category Bindings for the Text Widget ntext Indentation for # Meta category the Text Widget ntext Word Boundary Detection for # Meta category the Text Widget # Meta description Alternative Bindings for the Text Widget Alternative # Meta description Bindings for the Text Widget ntext Indentation for # Meta description the Text Widget ntext Word Boundary Detection for # Meta description the Text Widget # Meta license BSD # Meta platform tcl # Meta require {Tcl 8.5} # Meta require {Tk 8.5} # Meta subject bindtags text re_syntax regexp bindtags text # Meta subject bindtags text re_syntax regexp bindtags text # Meta subject re_syntax regexp # Meta summary ntext ntextBindings ntextIndent ntextWordBreak # @@ Meta End # ACTIVESTATE TEAPOT-PKG BEGIN DECLARE package provide ntext 0.81 # ACTIVESTATE TEAPOT-PKG END DECLARE # ACTIVESTATE TEAPOT-PKG END TM # ntext.tcl -- # derived from text.tcl # # This file defines the Ntext bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # # $Id: ntext.tcl,v 1.1 2007/06/21 21:05:27 hobbs Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. # Copyright (c) 1998 by Scriptics Corporation. # Copyright (c) 2005-2007 additions by Keith Nash. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ##### START OF CODE THAT IS MODIFIED text.tcl, Tk 8.5a5 = ActiveTcl 8.5beta6 #------------------------------------------------------------------------- # Elements of ::tk::Priv that are used in this file: # # afterId - If non-null, it means that auto-scanning is underway # and it gives the "after" id for the next auto-scan # command to be executed. # char - Character position on the line; kept in order # to allow moving up or down past short lines while # still remembering the desired position. # mouseMoved - Non-zero means the mouse has moved a significant # amount since the button went down (so, for example, # start dragging out a selection). # prevPos - Used when moving up or down lines via the keyboard. # Keeps track of the previous insert position, so # we can distinguish a series of ups and downs, all # in a row, from a new up or down. # selectMode - The style of selection currently underway: # char, word, or line. # x, y - Last known mouse coordinates for scanning # and auto-scanning. #------------------------------------------------------------------------- #------------------------------------------------------------------------- # The code below creates the Ntext class bindings for text widgets. #------------------------------------------------------------------------- package require Tcl 8.5 package require Tk 8.5 # Mouse bindings: use ::ntext::Bcount to deal with out-of-order multiple # clicks. This permits the bindings to be simplified bind Ntext <1> { set ::ntext::Bcount 1 ntext::TextButton1 %W %x %y %W tag remove sel 0.0 end } bind Ntext { set tk::Priv(x) %x set tk::Priv(y) %y ntext::TextSelectTo %W %x %y } # Inside the if: # The previous Button-1 event was not a single-click, but a double, triple, # or quadruple. # We can simplify the bindings if we ensure that a double-click is # *always* preceded by a single-click. # So in this case run the same code as <1> before doing bind Ntext { if {$::ntext::Bcount != 1} { set ::ntext::Bcount 1 ntext::TextButton1 %W %x %y %W tag remove sel 0.0 end } set ::ntext::Bcount 2 set tk::Priv(selectMode) word ntext::TextSelectTo %W %x %y catch {%W mark set insert sel.first} } # ignore an out-of-order triple click. This has no adverse consequences. bind Ntext { if {$::ntext::Bcount != 2} { continue } set ::ntext::Bcount 3 set tk::Priv(selectMode) line ntext::TextSelectTo %W %x %y catch {%W mark set insert sel.first} } # don't care if a quadruple click is out-of-order (i.e. follows a quadruple # click, not a triple click). bind Ntext { set ::ntext::Bcount 4 } bind Ntext { set ::ntext::Bcount 1 if {(!$::ntext::classicMouseSelect) && ([%W tag ranges sel] eq "")} { # Move the selection anchor mark to the old insert mark # Should the mark's gravity be set? %W mark set tk::anchor%W insert } if {$::ntext::classicAnchor} { tk::TextResetAnchor %W @%x,%y # if sel exists, sets anchor to end furthest from x,y # changes anchor only, not insert } set tk::Priv(selectMode) char ntext::TextSelectTo %W %x %y } # Inside the outer if: # The previous Button-1 event was not a single-click, but a double, triple, # or quadruple. # We can simplify the bindings if we ensure that a double-click is # *always* preceded by a single-click. # So in this case run the same code as before doing bind Ntext { if {$::ntext::Bcount != 1} { set ::ntext::Bcount 1 if {(!$::ntext::classicMouseSelect) && ([%W tag ranges sel] eq "")} { # Move the selection anchor mark to the old insert mark # Should the mark's gravity be set? %W mark set tk::anchor%W insert } if {$::ntext::classicAnchor} { tk::TextResetAnchor %W @%x,%y # if sel exists, sets anchor to end furthest from x,y # changes anchor only, not insert } set tk::Priv(selectMode) char ntext::TextSelectTo %W %x %y } set ::ntext::Bcount 2 set tk::Priv(selectMode) word ntext::TextSelectTo %W %x %y 1 } # ignore an out-of-order triple click. This has no adverse consequences. bind Ntext { if {$::ntext::Bcount != 2} { continue } set ::ntext::Bcount 3 set tk::Priv(selectMode) line ntext::TextSelectTo %W %x %y } # don't care if a quadruple click is out-of-order (i.e. follows a quadruple # click, not a triple click). bind Ntext { set ::ntext::Bcount 4 } bind Ntext { set tk::Priv(x) %x set tk::Priv(y) %y ntext::TextAutoScan %W } bind Ntext { tk::CancelRepeat } bind Ntext { tk::CancelRepeat } bind Ntext { %W mark set insert @%x,%y if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext { # nothing } bind Ntext { # nothing } bind Ntext { tk::TextSetCursor %W insert-1displayindices } bind Ntext { tk::TextSetCursor %W insert+1displayindices } bind Ntext { tk::TextSetCursor %W [tk::TextUpDownLine %W -1] } bind Ntext { tk::TextSetCursor %W [tk::TextUpDownLine %W 1] } bind Ntext { tk::TextKeySelect %W [%W index {insert - 1displayindices}] } bind Ntext { tk::TextKeySelect %W [%W index {insert + 1displayindices}] } bind Ntext { tk::TextKeySelect %W [tk::TextUpDownLine %W -1] } bind Ntext { tk::TextKeySelect %W [tk::TextUpDownLine %W 1] } bind Ntext { tk::TextSetCursor %W \ [tk::TextPrevPos %W insert ntext::new_startOfPreviousWord] } bind Ntext { tk::TextSetCursor %W [ntext::TextNextWord %W insert] } bind Ntext { tk::TextSetCursor %W [tk::TextPrevPara %W insert] } bind Ntext { tk::TextSetCursor %W [tk::TextNextPara %W insert] } bind Ntext { tk::TextKeySelect %W \ [tk::TextPrevPos %W insert ntext::new_startOfPreviousWord] } bind Ntext { tk::TextKeySelect %W [ntext::TextNextWord %W insert] } bind Ntext { tk::TextKeySelect %W [tk::TextPrevPara %W insert] } bind Ntext { tk::TextKeySelect %W [tk::TextNextPara %W insert] } bind Ntext { tk::TextSetCursor %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext { tk::TextKeySelect %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext { tk::TextSetCursor %W [ntext::TextScrollPages %W 1 preScroll] } bind Ntext { tk::TextKeySelect %W [ntext::TextScrollPages %W 1 preScroll] } bind Ntext { %W xview scroll -1 page } bind Ntext { %W xview scroll 1 page } bind Ntext { tk::TextSetCursor %W [::ntext::HomeIndex %W insert] } bind Ntext { tk::TextKeySelect %W [::ntext::HomeIndex %W insert] } bind Ntext { tk::TextSetCursor %W [::ntext::EndIndex %W insert] } bind Ntext { tk::TextKeySelect %W [::ntext::EndIndex %W insert] } bind Ntext { tk::TextSetCursor %W 1.0 } bind Ntext { tk::TextKeySelect %W 1.0 } bind Ntext { tk::TextSetCursor %W {end - 1 indices} } bind Ntext { tk::TextKeySelect %W {end - 1 indices} } bind Ntext { if {[%W cget -state] eq "normal"} { ntext::TextInsert %W \t focus %W break } } bind Ntext { # Needed only to keep binding from triggering; doesn't # have to actually do anything. break } bind Ntext { focus [tk_focusNext %W] } bind Ntext { focus [tk_focusPrev %W] } bind Ntext { if {$::ntext::classicExtras} { ntext::TextInsert %W \t } } bind Ntext { ntext::TextInsert %W \n if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext { if {[%W tag nextrange sel 1.0 end] ne ""} { set ::ntext::OldFirst [%W index sel.first] %W delete sel.first sel.last ntext::AdjustIndentOneLine %W $::ntext::OldFirst } else { %W delete insert ntext::AdjustIndentOneLine %W insert %W see insert } } bind Ntext { if {[%W tag nextrange sel 1.0 end] ne ""} { set ::ntext::OldFirst [%W index sel.first] %W delete sel.first sel.last ntext::AdjustIndentOneLine %W $::ntext::OldFirst } elseif {[%W compare insert != 1.0]} { %W delete insert-1c ntext::AdjustIndentOneLine %W insert %W see insert } } bind Ntext { if {$::ntext::classicExtras} { %W mark set tk::anchor%W insert } } bind Ntext