From e25738a13d8eea6c48b7a09321b17cf3077e145e Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Mon, 22 Jul 2024 03:28:57 -0700 Subject: [PATCH] code etc building and working with new textbuf.Lines changes --- code/appbar.go | 2 +- code/commandbufs.go | 8 +++----- code/editor.go | 20 ++++++++------------ code/findpanel.go | 4 ++-- code/spellpanel.go | 8 ++++---- code/symbolspanel.go | 4 ++-- mail/send.go | 3 ++- terminal/app.go | 5 +++-- 8 files changed, 25 insertions(+), 29 deletions(-) diff --git a/code/appbar.go b/code/appbar.go index 710270a3..637c567d 100644 --- a/code/appbar.go +++ b/code/appbar.go @@ -339,7 +339,7 @@ func (cv *Code) AddChooserFiles(ac *core.Chooser) { func (cv *Code) AddChooserSymbols(ac *core.Chooser) { ac.AddItemsFunc(func() { tv := cv.ActiveTextEditor() - if tv == nil || tv.Buffer == nil || !tv.Buffer.Highlighting.UsingParse() { + if tv == nil || tv.Buffer == nil || !tv.Buffer.Highlighter.UsingParse() { return } pfs := tv.Buffer.ParseState.Done() diff --git a/code/commandbufs.go b/code/commandbufs.go index d8636882..b54e19ea 100644 --- a/code/commandbufs.go +++ b/code/commandbufs.go @@ -24,16 +24,14 @@ func (cv *Code) RecycleCmdBuf(cmdName string) (*texteditor.Buffer, bool) { cv.CmdBufs = make(map[string]*texteditor.Buffer, 20) } if buf, has := cv.CmdBufs[cmdName]; has { - buf.NewBuffer(0) + buf.SetText(nil) return buf, false } buf := texteditor.NewBuffer() - buf.NewBuffer(0) + buf.SetText(nil) cv.CmdBufs[cmdName] = buf buf.Autosave = false - // buf.Info.Known = fileinfo.Bash - // buf.Info.Mime = fileinfo.MimeString(fileinfo.Bash) - // buf.Hi.Lang = "Bash" + buf.SetLanguage(fileinfo.Bash) return buf, true } diff --git a/code/editor.go b/code/editor.go index f7d503e7..1c0e06b3 100644 --- a/code/editor.go +++ b/code/editor.go @@ -94,7 +94,7 @@ func (cv *Code) LookupFun(data any, text string, posLine, posChar int) (ld compl title := "Lookup: " + text tb := texteditor.NewBuffer().SetText(txt).SetFilename(ld.Filename) - tb.Highlighting.Style = core.AppearanceSettings.Highlighting + tb.SetHighlighting(core.AppearanceSettings.Highlighting) tb.Options.LineNumbers = cv.Settings.Editor.LineNumbers d := core.NewBody().AddTitle(title).AddText(prmpt).SetData(&ld) @@ -333,14 +333,12 @@ func (cv *Code) DiffFileNode(fna *filetree.Node, fnmB core.Filename) { //types:a // returns a string report thereof. func (cv *Code) CountWords() string { //types:add av := cv.ActiveTextEditor() - if av.Buffer == nil || av.Buffer.NumLines <= 0 { + if av.Buffer == nil || av.Buffer.NumLines() <= 0 { return "empty" } - av.Buffer.LinesMu.RLock() - defer av.Buffer.LinesMu.RUnlock() - ll := av.Buffer.NumLines - 1 - reg := textbuf.NewRegion(0, 0, ll, len(av.Buffer.Lines[ll])) - words, lines := textbuf.CountWordsLinesRegion(av.Buffer.Lines, reg) + ll := av.Buffer.NumLines() - 1 + reg := textbuf.NewRegion(0, 0, ll, av.Buffer.NumLines()) + words, lines := av.Buffer.CountWordsLinesRegion(reg) return fmt.Sprintf("File: %s Words: %d Lines: %d\n", fsx.DirAndFile(string(av.Buffer.Filename)), words, lines) } @@ -348,16 +346,14 @@ func (cv *Code) CountWords() string { //types:add // if no selection, returns numbers for entire file. func (cv *Code) CountWordsRegion() string { //types:add av := cv.ActiveTextEditor() - if av.Buffer == nil || av.Buffer.NumLines <= 0 { + if av.Buffer == nil || av.Buffer.NumLines() <= 0 { return "empty" } if !av.HasSelection() { return cv.CountWords() } - av.Buffer.LinesMu.RLock() - defer av.Buffer.LinesMu.RUnlock() sel := av.Selection() - words, lines := textbuf.CountWordsLinesRegion(av.Buffer.Lines, sel.Reg) + words, lines := av.Buffer.CountWordsLinesRegion(sel.Reg) return fmt.Sprintf("File: %s Words: %d Lines: %d\n", fsx.DirAndFile(string(av.Buffer.Filename)), words, lines) } @@ -404,7 +400,7 @@ func (cv *Code) OpenFileURL(ur string, ftv *texteditor.Editor) bool { fpath := up.Path[1:] // has double // cdpath := "" if ftv != nil && ftv.Buffer != nil { // get cd path for non-pathed fnames - cdln := ftv.Buffer.BytesLine(0) + cdln := ftv.Buffer.LineBytes(0) if bytes.HasPrefix(cdln, []byte("cd ")) { fmidx := bytes.Index(cdln, []byte(" (from: ")) if fmidx > 0 { diff --git a/code/findpanel.go b/code/findpanel.go index e0085f75..246f22d1 100644 --- a/code/findpanel.go +++ b/code/findpanel.go @@ -227,7 +227,7 @@ func (fv *FindPanel) ReplaceAction() bool { // delete the link for the just done replace ftvln := ftv.CursorPos.Ln st := lexer.Pos{Ln: ftvln, Ch: 0} - len := len(ftv.Buffer.Lines[ftvln]) + len := ftv.Buffer.LineLen(ftvln) en := lexer.Pos{Ln: ftvln, Ch: len} ftv.Buffer.DeleteText(st, en, texteditor.EditSignal) } @@ -402,7 +402,7 @@ func (fv *FindPanel) makeFindToolbar(p *tree.Plan) { } fvtv := fv.TextEditor() if fvtv != nil { - fvtv.Buffer.NewBuffer(0) + fvtv.Buffer.SetText(nil) } } else { stringsx.InsertFirstUnique(&fv.Params().FindHist, find, core.SystemSettings.SavedPathsMax) diff --git a/code/spellpanel.go b/code/spellpanel.go index b91f40a0..6c15fc00 100644 --- a/code/spellpanel.go +++ b/code/spellpanel.go @@ -142,7 +142,7 @@ func (sv *SpellPanel) Init() { tv.QReplaceStart(sv.UnkWord, sv.ChangeText().Text(), false) tv.QReplaceReplaceAll(0) sv.LastAction = w - sv.Errs = tv.Buffer.AdjustedTagsImpl(sv.Errs, sv.CurLn) // update tags + sv.Errs = tv.Buffer.AdjustedTagsLine(sv.Errs, sv.CurLn) // update tags sv.CheckNext() }) }) @@ -209,7 +209,7 @@ func (sv *SpellPanel) CheckNext() { for { if sv.CurIndex < len(sv.Errs) { lx := sv.Errs[sv.CurIndex] - word := string(lx.Src(tv.Buffer.Lines[sv.CurLn])) + word := string(lx.Src(tv.Buffer.Line(sv.CurLn))) _, known := spell.Spell.CheckWord(word) // could have been fixed by now.. if known { sv.CurIndex++ @@ -233,7 +233,7 @@ func (sv *SpellPanel) CheckNext() { } sv.UnkLex = sv.Errs[sv.CurIndex] sv.CurIndex++ - sv.UnkWord = string(sv.UnkLex.Src(tv.Buffer.Lines[sv.CurLn])) + sv.UnkWord = string(sv.UnkLex.Src(tv.Buffer.Line(sv.CurLn))) sv.Suggest, _ = spell.Spell.CheckWord(sv.UnkWord) uf := sv.UnknownText() @@ -287,7 +287,7 @@ func (sv *SpellPanel) Change() { en := sv.UnkEndPos() ct := sv.ChangeText() tv.Buffer.ReplaceText(st, en, st, ct.Text(), texteditor.EditSignal, texteditor.ReplaceNoMatchCase) - nwrs := tv.Buffer.AdjustedTagsImpl(sv.Errs, sv.CurLn) // update tags + nwrs := tv.Buffer.AdjustedTagsLine(sv.Errs, sv.CurLn) // update tags if len(nwrs) == len(sv.Errs)-1 && sv.CurIndex > 0 { // Adjust got rid of changed one.. sv.CurIndex-- } diff --git a/code/symbolspanel.go b/code/symbolspanel.go index 6a947e97..13d19d00 100644 --- a/code/symbolspanel.go +++ b/code/symbolspanel.go @@ -198,7 +198,7 @@ func SelectSymbol(cv *Code, ssym syms.Symbol) { func (sv *SymbolsPanel) OpenPackage() { cv := sv.Code tv := cv.ActiveTextEditor() - if sv.Syms == nil || tv == nil || tv.Buffer == nil || !tv.Buffer.Highlighting.UsingParse() { + if sv.Syms == nil || tv == nil || tv.Buffer == nil || !tv.Buffer.Highlighter.UsingParse() { return } pfs := tv.Buffer.ParseState.Done() @@ -214,7 +214,7 @@ func (sv *SymbolsPanel) OpenPackage() { func (sv *SymbolsPanel) OpenFile() { cv := sv.Code tv := cv.ActiveTextEditor() - if sv.Syms == nil || tv == nil || tv.Buffer == nil || !tv.Buffer.Highlighting.UsingParse() { + if sv.Syms == nil || tv == nil || tv.Buffer == nil || !tv.Buffer.Highlighter.UsingParse() { return } pfs := tv.Buffer.ParseState.Done() diff --git a/mail/send.go b/mail/send.go index 13235cf0..1973be17 100644 --- a/mail/send.go +++ b/mail/send.go @@ -10,6 +10,7 @@ import ( "log/slog" "time" + "cogentcore.org/core/base/fileinfo" "cogentcore.org/core/core" "cogentcore.org/core/events" "cogentcore.org/core/styles" @@ -35,7 +36,7 @@ func (a *App) Compose() { //types:add b := core.NewBody().AddTitle("Send message") core.NewForm(b).SetStruct(a.ComposeMessage) ed := texteditor.NewEditor(b) - ed.Buffer.SetLanguage("md") + ed.Buffer.SetLanguage(fileinfo.Markdown) ed.Buffer.Options.LineNumbers = false ed.Styler(func(s *styles.Style) { s.SetMono(false) diff --git a/terminal/app.go b/terminal/app.go index 4e60aa4a..223db4c7 100644 --- a/terminal/app.go +++ b/terminal/app.go @@ -17,6 +17,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/exec" + "cogentcore.org/core/base/fileinfo" "cogentcore.org/core/base/strcase" "cogentcore.org/core/colors" "cogentcore.org/core/core" @@ -78,7 +79,7 @@ func (a *App) Init() { w.SetText(a.Dir) }) tree.AddChild(w, func(w *texteditor.Editor) { - w.Buffer.SetLanguage("go") + w.Buffer.SetLanguage(fileinfo.Go) w.Buffer.Options.LineNumbers = false w.OnKeyChord(func(e events.Event) { @@ -153,8 +154,8 @@ func (a *App) RunCmd(cmd string, cmds *core.Frame, dir *core.Text) error { var ib []byte buf := texteditor.NewBuffer() - buf.NewBuffer(0) buf.Options.LineNumbers = false + buf.SetText(nil) ed := texteditor.NewEditor(cfr).SetBuffer(buf) ed.Styler(func(s *styles.Style) {