1791 proc get_index {txtt position args} {
1805 array set opts $args
1808 set index $opts(-startpos)
1813 if {[$txtt compare "$opts(-startpos) display linestart" > "$opts(-startpos)-$opts(-num) display chars"]} {
1814 set index "$opts(-startpos) display linestart"
1816 set index "$opts(-startpos)-$opts(-num) display chars"
1820 if {[$txtt compare "$opts(-startpos) display lineend" < "$opts(-startpos)+$opts(-num) display chars"]} {
1821 set index "$opts(-startpos) display lineend"
1823 set index "$opts(-startpos)+$opts(-num) display chars"
1827 if {[
set $opts(-column)] eq ""} {
1828 set $opts(-column) [
lindex [
split [$txtt index $opts(-startpos)] .] 1]
1830 set index $opts(-startpos)
1831 for {
set i 0} {$i < $opts(-num)} {
incr i} {
1832 set index [$txtt index "$index linestart-1 display lines"]
1834 set index [
lindex [
split $index .] 0].[
set $opts(-column)]
1837 if {[
set $opts(-column)] eq ""} {
1838 set $opts(-column) [
lindex [
split [$txtt index $opts(-startpos)] .] 1]
1840 set index $opts(-startpos)
1841 for {
set i 0} {$i < $opts(-num)} {
incr i} {
1842 if {[$txtt compare [
set index [$txtt index "$index lineend+1 display lines"]] == end]} {
1843 set index [$txtt index "end-1c"]
1847 set index [
lindex [
split $index .] 0].[
set $opts(-column)]
1850 if {[$txtt get -displaychars 1.0] eq ""} {
1851 set index "1.0+1 display chars"
1856 last {
set index "end"}
1857 char {
set index [
get_char $txtt $opts(-dir) $opts(-num) $opts(-startpos)]}
1859 if {$opts(-dir) eq "next"} {
1860 set index "$opts(-startpos)+$opts(-num) display chars"
1862 set index "$opts(-startpos)-$opts(-num) display chars"
1865 findchar {
set index [
find_char $txtt $opts(-dir) $opts(-char) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1866 betweenchar {
set index [
between_char $txtt $opts(-dir) $opts(-char) $opts(-startpos)]}
1868 if {$opts(-num) == 0} {
1869 set index $opts(-startpos)
1870 }
elseif {$opts(-dir) eq "next"} {
1871 if {[$txtt compare [
set index [$txtt index "$opts(-startpos)+$opts(-num) display lines"]] == end]} {
1872 set index [$txtt index "$index-1 display lines"]
1875 set index [$txtt index "$opts(-startpos)-$opts(-num) display lines"]
1877 if {[lsearch [$txtt tag names "$index linestart"] __prewhite] != -1} {
1878 set index [
lindex [$txtt tag nextrange __prewhite "$index linestart"] 1]-1c
1880 set index "$index lineend"
1884 set line [
expr [
lindex [
split [$txtt index $opts(-startpos)] .] 0] + ($opts(-num) - 1)]
1885 set index "$line.0+[
string length [
string trimright [$txtt get $line.0 $line.end]]]c"
1887 wordstart {
set index [
get_wordstart $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1888 wordend {
set index [
get_wordend $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1889 WORDstart {
set index [
get_WORDstart $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1890 WORDend {
set index [
get_WORDend $txtt $opts(-dir) $opts(-num) $opts(-startpos) $opts(-exclusive)]}
1891 column {
set index [
lindex [
split [$txtt index $opts(-startpos)] .] 0].[
expr $opts(-num) - 1]}
1893 if {[lsearch [$txtt tag names "$opts(-num).0"] __prewhite] != -1} {
1894 set index [
lindex [$txtt tag nextrange __prewhite "$opts(-num).0"] 1]-1c
1896 set index "$opts(-num).0 lineend"
1900 if {$opts(-num) > 1} {
1901 if {[$txtt compare [
set index [$txtt index "$opts(-startpos)+[
expr $opts(-num) - 1] display lines linestart"]] == end]} {
1904 set index "$index+1 display chars"
1907 set index [$txtt index "$opts(-startpos) linestart+1 display chars"]
1909 if {[$txtt compare "$index-1 display chars" >= "$index linestart"]} {
1910 set index "$index-1 display chars"
1914 if {$opts(-num) == 1} {
1915 set index "$opts(-startpos) lineend"
1917 set index [$txtt index "$opts(-startpos)+[
expr $opts(-num) - 1] display lines"]
1918 set index "$index lineend"
1921 dispstart {
set index "@0,[
lindex [$txtt bbox $opts(-startpos)] 1]"}
1922 dispmid {
set index "@[
expr [
winfo width $txtt] / 2],[
lindex [$txtt bbox $opts(-startpos)] 1]"}
1923 dispend {
set index "@[
winfo width $txtt],[
lindex [$txtt bbox $opts(-startpos)] 0]"}
1924 sentence {
set index [
get_sentence $txtt $opts(-dir) $opts(-num) $opts(-startpos)]}
1925 paragraph {
set index [
get_paragraph $txtt $opts(-dir) $opts(-num) $opts(-startpos)]}
1926 screentop {
set index "@0,0"}
1927 screenmid {
set index "@0,[
expr [
winfo height $txtt] / 2]"}
1928 screenbot {
set index "@0,[
winfo height $txtt]"}
1930 if {[regexp $patterns(pnumber) [$txtt get "$opts(-startpos) linestart" $opts(-startpos)] match]} {
1931 set index "$opts(-startpos)-[
string length $match]c"
1935 if {[regexp $patterns(nnumber) [$txtt get $opts(-startpos) "$opts(-startpos) lineend"] match]} {
1936 set index "$opts(-startpos)+[
expr [
string length $match] - 1]c"
1940 if {[regexp $patterns(pspace) [$txtt get "$opts(-startpos) linestart" $opts(-startpos)] match]} {
1941 set index "$opts(-startpos)-[
string length $match]c"
1945 if {[regexp $patterns(nspace) [$txtt get $opts(-startpos) "$opts(-startpos) lineend"] match]} {
1946 set index "$opts(-startpos)+[
expr [
string length $match] - 1]c"
1950 set insert [$txtt index insert]
1952 if {[
incr opts(-num) -1] == 0} {
1953 set index [
expr {$opts(-exclusive) ? [lindex $ranges 1] : [lindex $ranges 0]}]
1956 $txtt mark set insert "[
lindex $ranges 0]-1c"
1959 $txtt mark set insert $insert
1962 set insert [$txtt index insert]
1964 if {[
incr opts(-num) -1] == 0} {
1965 set index [
expr {$opts(-exclusive) ? [lindex $ranges 2] : [lindex $ranges 3]}]
1968 $txtt mark set insert "[
lindex $ranges 0]-1c"
1971 $txtt mark set insert $insert
1976 if {$opts(-forceadjust) ne ""} {
1977 set index [$txtt index "$index$opts(-forceadjust)"]
1978 }
elseif {($index ne $opts(-startpos)) && ($opts(-adjust) ne "")} {
1979 set index [$txtt index "$index$opts(-adjust)"]