Skip to content

Commit

Permalink
start / end line in textview now works for wrapped lines. fixed crash…
Browse files Browse the repository at this point in the history
… in cursor updating.
  • Loading branch information
Randall C. O'Reilly committed Sep 21, 2018
1 parent 968bb76 commit e9a3868
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ Currently at a **pre-beta** level (**DON'T RECOMMEND USING RIGHT NOW** -- come b

# TODO

* entering newlines in *middle of* existing wrapped line mode not re-rendering properly, e.g., in .md files. Just go to "line" in above line and hit enter to reproduce..

* scrolling in tabview is reverting to first tab -- tried fixing move2d but didn't work?

* would be a lot faster if textbuf held the markup text and views just read off of that -- then switching buffers would be instant. might make it easier to protect the updating too -- views don't get a crack at anything until it is updated.. -- also ideally do a diff for re-open, and only re-highlight areas that are changed. as a first pass, at least testing for identity would save a lot of time for most post-save actions.

* Ctrl+A start of line should go to start of wrapped line, not overall start of line, for multi-line editing.

* select highlight on first line of multi-line not showing until you get to char1 -- also more generally the select logic for resetting the start of select needs to be fixed to work like emacs..

* bold in **Markdown** causing a repeat of last two letters! really throws things off.

* fix embedded tags in pre html parser -- just need a simple stack..

* getting mysterious crashes in clearClip and closewindow on mac in cocoa.m -- hard to debug what is going on.. :(

* drag on textview should prevent DND -- dnd not getting "processed"
Expand Down Expand Up @@ -156,3 +158,5 @@ Currently at a **pre-beta** level (**DON'T RECOMMEND USING RIGHT NOW** -- come b





55 changes: 42 additions & 13 deletions giv/textview.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type TextView struct {
reLayout bool
lastRecenter int
lastFilename gi.FileName
lastWasTab bool
}

var KiT_TextView = kit.Types.AddType(&TextView{}, TextViewProps)
Expand Down Expand Up @@ -959,8 +960,24 @@ func (tv *TextView) CursorStartLine() {
defer tv.Viewport.Win.UpdateEnd(updt)
tv.ValidateCursor()
org := tv.CursorPos
tv.CursorPos.Ch = 0
tv.CursorCol = tv.CursorPos.Ch
pos := tv.CursorPos

gotwrap := false
if wln := tv.WrappedLines(pos.Ln); wln > 1 {
si, ri, ok := tv.WrappedLineNo(pos)
if ok && si > 0 {
ri = 0
nwc, _ := tv.Renders[pos.Ln].SpanPosToRuneIdx(si, ri)
pos.Ch = nwc
tv.CursorPos = pos
tv.CursorCol = ri
gotwrap = true
}
}
if !gotwrap {
tv.CursorPos.Ch = 0
tv.CursorCol = tv.CursorPos.Ch
}
tv.SetCursor(tv.CursorPos)
tv.ScrollCursorToLeft()
tv.RenderCursor(true)
Expand Down Expand Up @@ -989,15 +1006,25 @@ func (tv *TextView) CursorEndLine() {
defer tv.Viewport.Win.UpdateEnd(updt)
tv.ValidateCursor()
org := tv.CursorPos
tv.CursorPos.Ch = len(tv.Buf.Lines[tv.CursorPos.Ln])
if wln := tv.WrappedLines(tv.CursorPos.Ln); wln > 1 {
si, ri, ok := tv.WrappedLineNo(tv.CursorPos)
if ok && si > 0 {
pos := tv.CursorPos

gotwrap := false
if wln := tv.WrappedLines(pos.Ln); wln > 1 {
si, ri, ok := tv.WrappedLineNo(pos)
if ok {
// todo: don't have a good way to put cursor at end of wrapped line..
ri = len(tv.Renders[pos.Ln].Spans[si].Text)
tv.CursorCol = ri
} else {
tv.CursorCol = tv.CursorPos.Ch
nwc, _ := tv.Renders[pos.Ln].SpanPosToRuneIdx(si, ri)
pos.Ch = nwc
tv.CursorPos = pos
gotwrap = true
}
}
if !gotwrap {
tv.CursorPos.Ch = len(tv.Buf.Lines[tv.CursorPos.Ln])
tv.CursorCol = tv.CursorPos.Ch
}
tv.SetCursor(tv.CursorPos)
tv.ScrollCursorToRight()
tv.RenderCursor(true)
Expand Down Expand Up @@ -2009,7 +2036,7 @@ func (tv *TextView) RenderCursor(on bool) {
if tv.Renders == nil {
return
}
if tv.PushBounds() {
if tv.InBounds() {
sp := tv.CursorSprite()
if on {
win.ActivateSprite(sp.Nm)
Expand All @@ -2018,8 +2045,7 @@ func (tv *TextView) RenderCursor(on bool) {
}
sp.Geom.Pos = tv.CharStartPos(tv.CursorPos).ToPointFloor()
win.RenderOverlays() // needs an explicit call!
tv.PopBounds()
win.UpdateSig() // publish
win.UpdateSig() // publish
}
}

Expand Down Expand Up @@ -2175,7 +2201,9 @@ func (tv *TextView) VisSizes() {
// RenderAllLines displays all the visible lines on the screen -- this is
// called outside of update process and has its own bounds check and updating
func (tv *TextView) RenderAllLines() {
if tv.PushBounds() {
if tv.InBounds() {
rs := &tv.Viewport.Render
rs.PushBounds(tv.VpBBox)
vp := tv.Viewport
updt := vp.Win.UpdateStart()
tv.RenderAllLinesInBounds()
Expand Down Expand Up @@ -2292,14 +2320,15 @@ func (tv *TextView) RenderLines(st, ed int) bool {
if st > ed {
return false
}
if tv.PushBounds() {
if tv.InBounds() {
vp := tv.Viewport
updt := vp.Win.UpdateStart()
sty := &tv.Sty
rs := &vp.Render
pc := &rs.Paint
pos := tv.RenderStartPos()
var boxMin, boxMax gi.Vec2D
rs.PushBounds(tv.VpBBox)
// first get the box to fill
visSt := -1
visEd := -1
Expand Down
5 changes: 2 additions & 3 deletions textfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ func (tf *TextField) RenderCursor(on bool) {
if win == nil {
return
}
if tf.PushBounds() {
if tf.InBounds() {
sp := tf.CursorSprite()
if on {
win.ActivateSprite(sp.Nm)
Expand All @@ -740,8 +740,7 @@ func (tf *TextField) RenderCursor(on bool) {
}
sp.Geom.Pos = tf.CharStartPos(tf.CursorPos).ToPointFloor()
win.RenderOverlays() // needs an explicit call!
tf.PopBounds()
win.UpdateSig() // publish
win.UpdateSig() // publish
}
}

Expand Down
8 changes: 8 additions & 0 deletions widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ func (wb *WidgetBase) FullReRenderIfNeeded() bool {
return false
}

// InBounds returns true if our VpBBox is non-empty (and other stuff is non-nil)
func (wb *WidgetBase) InBounds() bool {
if wb.This == nil || wb.Viewport == nil {
return false
}
return !wb.VpBBox.Empty()
}

// PushBounds pushes our bounding-box bounds onto the bounds stack if non-empty
// -- this limits our drawing to our own bounding box, automatically -- must
// be called as first step in Render2D returns whether the new bounds are
Expand Down

0 comments on commit e9a3868

Please sign in to comment.