Skip to content

Commit

Permalink
Fix issue #16: showing the tick at start of selection
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-lalonde committed Apr 1, 2018
1 parent a03a1b1 commit fb09b37
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions frame/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (f *Frame) DrawSel(pt image.Point, p0, p1 int, highlighted bool) {
// If we should just show the tick, do that and return.
if p0 == p1 {
f.Tick(pt, highlighted)
f.Display.Flush() // To show the tick.
f.P0 = p0
f.P1 = p1
return
Expand Down
38 changes: 37 additions & 1 deletion text.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,11 +1307,47 @@ func (t *Text) SetSelect(q0, q1 int) {
if p1 > (t.fr.GetFrameFillStatus().Nchars) {
p1 = (t.fr.GetFrameFillStatus().Nchars)
}
if(p0==getP0(t.fr) && p1==getP1(t.fr)){
if(p0 == p1 && ticked != t.fr.Ticked) {
t.fr.Tick(t.fr.Ptofchar(p0), ticked);
}
return;
}
if p0 > p1 {
panic(fmt.Sprintf("acme: textsetselect p0=%d p1=%d q0=%v q1=%v t.org=%d nchars=%d", p0, p1, q0, q1, t.org, t.fr.GetFrameFillStatus().Nchars))
}

t.fr.DrawSel(t.fr.Ptofchar(p0), p0, p1, ticked)
/* screen disagrees with desired selection */
if getP1(t.fr)<=p0 || p1<=getP0(t.fr) || p0==p1 || getP1(t.fr)==getP0(t.fr) {
/* no overlap or too easy to bother trying */
t.fr.DrawSel(t.fr.Ptofchar(getP0(t.fr)), getP0(t.fr), getP1(t.fr), false);
if p0 != p1 || ticked {
t.fr.DrawSel(t.fr.Ptofchar(p0), p0, p1, true);
}
goto Return;
}
/* overlap; avoid unnecessary painting */
if p0 < getP0(t.fr) {
/* extend selection backwards */
t.fr.DrawSel(t.fr.Ptofchar(p0), p0, getP0(t.fr), true);
}else {
if p0 > getP0(t.fr) {
/* trim first part of selection */
t.fr.DrawSel(t.fr.Ptofchar(getP0(t.fr)), getP0(t.fr), p0, false);
}
}
if p1 > getP1(t.fr) {
/* extend selection forwards */
t.fr.DrawSel(t.fr.Ptofchar(getP1(t.fr)), getP1(t.fr), p1, true);
}else {
if p1 < getP1(t.fr) {
/* trim last part of selection */
t.fr.DrawSel(t.fr.Ptofchar(p1), p1, getP1(t.fr), false);
}
}

Return:
t.fr.SetSelectionExtent(p0,p1)
}

func selrestore(f *frame.Frame, pt0 image.Point, p0, p1 int) {
Expand Down

0 comments on commit fb09b37

Please sign in to comment.