Skip to content

Commit

Permalink
rename textbuf -> text
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jul 23, 2024
1 parent 21b2d0c commit aa22336
Show file tree
Hide file tree
Showing 25 changed files with 121 additions and 121 deletions.
16 changes: 8 additions & 8 deletions filetree/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"cogentcore.org/core/base/fileinfo"
"cogentcore.org/core/core"
"cogentcore.org/core/texteditor/textbuf"
"cogentcore.org/core/texteditor/text"
"cogentcore.org/core/tree"
)

Expand Down Expand Up @@ -43,7 +43,7 @@ const (
type SearchResults struct {
Node *Node
Count int
Matches []textbuf.Match
Matches []text.Match
}

// Search returns list of all nodes starting at given node of given
Expand Down Expand Up @@ -101,7 +101,7 @@ func Search(start *Node, find string, ignoreCase, regExp bool, loc FindLocation,
// }
}
var cnt int
var matches []textbuf.Match
var matches []text.Match
if sfn.isOpen() && sfn.Buffer != nil {
if regExp {
cnt, matches = sfn.Buffer.SearchRegexp(re)
Expand All @@ -110,9 +110,9 @@ func Search(start *Node, find string, ignoreCase, regExp bool, loc FindLocation,
}
} else {
if regExp {
cnt, matches = textbuf.SearchFileRegexp(string(sfn.Filepath), re)
cnt, matches = text.SearchFileRegexp(string(sfn.Filepath), re)
} else {
cnt, matches = textbuf.SearchFile(string(sfn.Filepath), fb, ignoreCase)
cnt, matches = text.SearchFile(string(sfn.Filepath), fb, ignoreCase)
}
}
if cnt > 0 {
Expand Down Expand Up @@ -175,7 +175,7 @@ func findAll(start *Node, find string, ignoreCase, regExp bool, langs []fileinfo
}
ofn := openPath(path)
var cnt int
var matches []textbuf.Match
var matches []text.Match
if ofn != nil && ofn.Buffer != nil {
if regExp {
cnt, matches = ofn.Buffer.SearchRegexp(re)
Expand All @@ -184,9 +184,9 @@ func findAll(start *Node, find string, ignoreCase, regExp bool, langs []fileinfo
}
} else {
if regExp {
cnt, matches = textbuf.SearchFileRegexp(path, re)
cnt, matches = text.SearchFileRegexp(path, re)
} else {
cnt, matches = textbuf.SearchFile(path, fb, ignoreCase)
cnt, matches = text.SearchFile(path, fb, ignoreCase)
}
}
if cnt > 0 {
Expand Down
4 changes: 2 additions & 2 deletions filetree/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"cogentcore.org/core/core"
"cogentcore.org/core/styles"
"cogentcore.org/core/texteditor"
"cogentcore.org/core/texteditor/textbuf"
"cogentcore.org/core/texteditor/text"
"cogentcore.org/core/tree"
)

Expand Down Expand Up @@ -333,7 +333,7 @@ func (fn *Node) blameVCS() ([]byte, error) {
return nil, errors.New("file not in vcs repo: " + string(fn.Filepath))
}
fnm := string(fn.Filepath)
fb, err := textbuf.FileBytes(fnm)
fb, err := text.FileBytes(fnm)
if err != nil {
return nil, err
}
Expand Down
42 changes: 21 additions & 21 deletions texteditor/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"cogentcore.org/core/parse/token"
"cogentcore.org/core/spell"
"cogentcore.org/core/texteditor/highlighting"
"cogentcore.org/core/texteditor/textbuf"
"cogentcore.org/core/texteditor/text"
)

// Buffer is a buffer of text, which can be viewed by [Editor](s).
Expand All @@ -40,7 +40,7 @@ import (
// Internally, the buffer represents new lines using \n = LF, but saving
// and loading can deal with Windows/DOS CRLF format.
type Buffer struct { //types:add
textbuf.Lines
text.Lines

// Filename is the filename of the file that was last loaded or saved.
// It is used when highlighting code.
Expand Down Expand Up @@ -124,12 +124,12 @@ const (
bufferMods

// bufferInsert signals that some text was inserted.
// data is textbuf.Edit describing change.
// data is text.Edit describing change.
// The Buf always reflects the current state *after* the edit.
bufferInsert

// bufferDelete signals that some text was deleted.
// data is textbuf.Edit describing change.
// data is text.Edit describing change.
// The Buf always reflects the current state *after* the edit.
bufferDelete

Expand All @@ -138,13 +138,13 @@ const (
// so should be used with a mutex
bufferMarkupUpdated

// bufferClosed signals that the textbuf was closed.
// bufferClosed signals that the text was closed.
bufferClosed
)

// signalEditors sends the given signal and optional edit info
// to all the [Editor]s for this [Buffer]
func (tb *Buffer) signalEditors(sig bufferSignals, edit *textbuf.Edit) {
func (tb *Buffer) signalEditors(sig bufferSignals, edit *text.Edit) {
for _, vw := range tb.editors {
vw.bufferSignal(sig, edit)
}
Expand Down Expand Up @@ -603,7 +603,7 @@ func (tb *Buffer) AutoSaveCheck() bool {

// AppendTextMarkup appends new text to end of buffer, using insert, returns
// edit, and uses supplied markup to render it.
func (tb *Buffer) AppendTextMarkup(text []byte, markup []byte, signal bool) *textbuf.Edit {
func (tb *Buffer) AppendTextMarkup(text []byte, markup []byte, signal bool) *text.Edit {
tbe := tb.Lines.AppendTextMarkup(text, markup)
if tbe != nil && signal {
tb.signalEditors(bufferInsert, tbe)
Expand All @@ -614,7 +614,7 @@ func (tb *Buffer) AppendTextMarkup(text []byte, markup []byte, signal bool) *tex
// AppendTextLineMarkup appends one line of new text to end of buffer, using
// insert, and appending a LF at the end of the line if it doesn't already
// have one. User-supplied markup is used. Returns the edit region.
func (tb *Buffer) AppendTextLineMarkup(text []byte, markup []byte, signal bool) *textbuf.Edit {
func (tb *Buffer) AppendTextLineMarkup(text []byte, markup []byte, signal bool) *text.Edit {
tbe := tb.Lines.AppendTextLineMarkup(text, markup)
if tbe != nil && signal {
tb.signalEditors(bufferInsert, tbe)
Expand Down Expand Up @@ -690,7 +690,7 @@ const (
// optionally signaling views after text lines have been updated.
// Sets the timestamp on resulting Edit to now.
// An Undo record is automatically saved depending on Undo.Off setting.
func (tb *Buffer) DeleteText(st, ed lexer.Pos, signal bool) *textbuf.Edit {
func (tb *Buffer) DeleteText(st, ed lexer.Pos, signal bool) *text.Edit {
tb.FileModCheck()
tb.setChanged()
tbe := tb.Lines.DeleteText(st, ed)
Expand All @@ -708,9 +708,9 @@ func (tb *Buffer) DeleteText(st, ed lexer.Pos, signal bool) *textbuf.Edit {

// deleteTextRect deletes rectangular region of text between start, end
// defining the upper-left and lower-right corners of a rectangle.
// Fails if st.Ch >= ed.Ch. Sets the timestamp on resulting textbuf.Edit to now.
// Fails if st.Ch >= ed.Ch. Sets the timestamp on resulting text.Edit to now.
// An Undo record is automatically saved depending on Undo.Off setting.
func (tb *Buffer) deleteTextRect(st, ed lexer.Pos, signal bool) *textbuf.Edit {
func (tb *Buffer) deleteTextRect(st, ed lexer.Pos, signal bool) *text.Edit {
tb.FileModCheck()
tb.setChanged()
tbe := tb.Lines.DeleteTextRect(st, ed)
Expand All @@ -730,7 +730,7 @@ func (tb *Buffer) deleteTextRect(st, ed lexer.Pos, signal bool) *textbuf.Edit {
// It inserts new text at given starting position, optionally signaling
// views after text has been inserted. Sets the timestamp on resulting Edit to now.
// An Undo record is automatically saved depending on Undo.Off setting.
func (tb *Buffer) insertText(st lexer.Pos, text []byte, signal bool) *textbuf.Edit {
func (tb *Buffer) insertText(st lexer.Pos, text []byte, signal bool) *text.Edit {
tb.FileModCheck() // will just revert changes if shouldn't have changed
tb.setChanged()
tbe := tb.Lines.InsertText(st, text)
Expand All @@ -746,12 +746,12 @@ func (tb *Buffer) insertText(st lexer.Pos, text []byte, signal bool) *textbuf.Ed
return tbe
}

// insertTextRect inserts a rectangle of text defined in given textbuf.Edit record,
// insertTextRect inserts a rectangle of text defined in given text.Edit record,
// (e.g., from RegionRect or DeleteRect), optionally signaling
// views after text has been inserted.
// Returns a copy of the Edit record with an updated timestamp.
// An Undo record is automatically saved depending on Undo.Off setting.
func (tb *Buffer) insertTextRect(tbe *textbuf.Edit, signal bool) *textbuf.Edit {
func (tb *Buffer) insertTextRect(tbe *text.Edit, signal bool) *text.Edit {
tb.FileModCheck() // will just revert changes if shouldn't have changed
tb.setChanged()
nln := tb.NumLines()
Expand All @@ -761,7 +761,7 @@ func (tb *Buffer) insertTextRect(tbe *textbuf.Edit, signal bool) *textbuf.Edit {
}
if signal {
if re.Reg.End.Ln >= nln {
ie := &textbuf.Edit{}
ie := &text.Edit{}
ie.Reg.Start.Ln = nln - 1
ie.Reg.End.Ln = re.Reg.End.Ln
tb.signalEditors(bufferInsert, ie)
Expand All @@ -779,8 +779,8 @@ func (tb *Buffer) insertTextRect(tbe *textbuf.Edit, signal bool) *textbuf.Edit {
// (typically same as delSt but not necessarily), optionally emitting a signal after the insert.
// if matchCase is true, then the lexer.MatchCase function is called to match the
// case (upper / lower) of the new inserted text to that of the text being replaced.
// returns the textbuf.Edit for the inserted text.
func (tb *Buffer) ReplaceText(delSt, delEd, insPos lexer.Pos, insTxt string, signal, matchCase bool) *textbuf.Edit {
// returns the text.Edit for the inserted text.
func (tb *Buffer) ReplaceText(delSt, delEd, insPos lexer.Pos, insTxt string, signal, matchCase bool) *text.Edit {
tbe := tb.Lines.ReplaceText(delSt, delEd, insPos, insTxt, matchCase)
if tbe == nil {
return tbe
Expand Down Expand Up @@ -815,7 +815,7 @@ func (tb *Buffer) savePosHistory(pos lexer.Pos) bool {
// Undo

// undo undoes next group of items on the undo stack
func (tb *Buffer) undo() []*textbuf.Edit {
func (tb *Buffer) undo() []*text.Edit {
autoSave := tb.batchUpdateStart()
defer tb.batchUpdateEnd(autoSave)
tbe := tb.Lines.Undo()
Expand All @@ -829,7 +829,7 @@ func (tb *Buffer) undo() []*textbuf.Edit {

// redo redoes next group of items on the undo stack,
// and returns the last record, nil if no more
func (tb *Buffer) redo() []*textbuf.Edit {
func (tb *Buffer) redo() []*text.Edit {
autoSave := tb.batchUpdateStart()
defer tb.batchUpdateEnd(autoSave)
tbe := tb.Lines.Redo()
Expand Down Expand Up @@ -883,7 +883,7 @@ func (tb *Buffer) DeleteLineColor(ln int) {
// indentLine indents line by given number of tab stops, using tabs or spaces,
// for given tab size (if using spaces) -- either inserts or deletes to reach target.
// Returns edit record for any change.
func (tb *Buffer) indentLine(ln, ind int) *textbuf.Edit {
func (tb *Buffer) indentLine(ln, ind int) *text.Edit {
autoSave := tb.batchUpdateStart()
defer tb.batchUpdateEnd(autoSave)
tbe := tb.Lines.IndentLine(ln, ind)
Expand Down Expand Up @@ -940,7 +940,7 @@ func (tb *Buffer) DiffBuffersUnified(ob *Buffer, context int) []byte {
astr := tb.Strings(true) // needs newlines for some reason
bstr := ob.Strings(true)

return textbuf.DiffLinesUnified(astr, bstr, context, string(tb.Filename), tb.Info.ModTime.String(),
return text.DiffLinesUnified(astr, bstr, context, string(tb.Filename), tb.Info.ModTime.String(),
string(ob.Filename), ob.Info.ModTime.String())
}

Expand Down
12 changes: 6 additions & 6 deletions texteditor/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"cogentcore.org/core/parse/complete"
"cogentcore.org/core/parse/lexer"
"cogentcore.org/core/parse/parser"
"cogentcore.org/core/texteditor/textbuf"
"cogentcore.org/core/texteditor/text"
)

// completeParse uses [parse] symbols and language; the string is a line of text
Expand Down Expand Up @@ -61,7 +61,7 @@ func completeEditParse(data any, text string, cursorPos int, comp complete.Compl
// lookupParse uses [parse] symbols and language; the string is a line of text
// up to point where user has typed.
// The data must be the *FileState from which the language type is obtained.
func lookupParse(data any, text string, posLine, posChar int) (ld complete.Lookup) {
func lookupParse(data any, txt string, posLine, posChar int) (ld complete.Lookup) {
sfs := data.(*parse.FileStates)
if sfs == nil {
// log.Printf("LookupPi: data is nil not FileStates or is nil - can't lookup\n")
Expand All @@ -80,15 +80,15 @@ func lookupParse(data any, text string, posLine, posChar int) (ld complete.Looku
// must set it in pi/parse directly -- so it is changed in the fileparse too
parser.GUIActive = true // note: this is key for debugging -- runs slower but makes the tree unique

ld = lp.Lang.Lookup(sfs, text, lexer.Pos{posLine, posChar})
ld = lp.Lang.Lookup(sfs, txt, lexer.Pos{posLine, posChar})
if len(ld.Text) > 0 {
TextDialog(nil, "Lookup: "+text, string(ld.Text))
TextDialog(nil, "Lookup: "+txt, string(ld.Text))
return ld
}
if ld.Filename != "" {
txt := textbuf.FileRegionBytes(ld.Filename, ld.StLine, ld.EdLine, true, 10) // comments, 10 lines back max
tx := text.FileRegionBytes(ld.Filename, ld.StLine, ld.EdLine, true, 10) // comments, 10 lines back max
prmpt := fmt.Sprintf("%v [%d:%d]", ld.Filename, ld.StLine, ld.EdLine)
TextDialog(nil, "Lookup: "+text+": "+prmpt, string(txt))
TextDialog(nil, "Lookup: "+txt+": "+prmpt, string(tx))
return ld
}

Expand Down
18 changes: 9 additions & 9 deletions texteditor/diffeditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"cogentcore.org/core/parse/token"
"cogentcore.org/core/styles"
"cogentcore.org/core/styles/states"
"cogentcore.org/core/texteditor/textbuf"
"cogentcore.org/core/texteditor/text"
"cogentcore.org/core/tree"
)

Expand Down Expand Up @@ -58,27 +58,27 @@ func DiffEditorDialogFromRevs(ctx core.Widget, repo vcs.Repo, file string, fbuf
if fbuf != nil {
bstr = fbuf.Strings(false)
} else {
fb, err := textbuf.FileBytes(file)
fb, err := text.FileBytes(file)
if err != nil {
core.ErrorDialog(ctx, err)
return nil, err
}
bstr = textbuf.BytesToLineStrings(fb, false) // don't add new lines
bstr = text.BytesToLineStrings(fb, false) // don't add new lines
}
} else {
fb, err := repo.FileContents(file, rev_b)
if err != nil {
core.ErrorDialog(ctx, err)
return nil, err
}
bstr = textbuf.BytesToLineStrings(fb, false) // don't add new lines
bstr = text.BytesToLineStrings(fb, false) // don't add new lines
}
fb, err := repo.FileContents(file, rev_a)
if err != nil {
core.ErrorDialog(ctx, err)
return nil, err
}
astr = textbuf.BytesToLineStrings(fb, false) // don't add new lines
astr = text.BytesToLineStrings(fb, false) // don't add new lines
if rev_a == "" {
rev_a = "HEAD"
}
Expand Down Expand Up @@ -141,10 +141,10 @@ type DiffEditor struct {
bufferB *Buffer

// aligned diffs records diff for aligned lines
alignD textbuf.Diffs
alignD text.Diffs

// diffs applied
diffs textbuf.DiffSelected
diffs text.DiffSelected

inInputEvent bool
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func (dv *DiffEditor) DiffStrings(astr, bstr []string) {
chg := colors.Scheme.Primary.Base

nd := len(dv.diffs.Diffs)
dv.alignD = make(textbuf.Diffs, nd)
dv.alignD = make(text.Diffs, nd)
var ab, bb [][]byte
absln := 0
bspc := []byte(" ")
Expand Down Expand Up @@ -444,7 +444,7 @@ func (dv *DiffEditor) tagWordDiffs() {
fla := lna.RuneStrings(ra)
flb := lnb.RuneStrings(rb)
nab := max(len(fla), len(flb))
ldif := textbuf.DiffLines(fla, flb)
ldif := text.DiffLines(fla, flb)
ndif := len(ldif)
if nab > 25 && ndif > nab/2 { // more than half of big diff -- skip
continue
Expand Down
Loading

0 comments on commit aa22336

Please sign in to comment.