Skip to content

Commit

Permalink
code etc building and working with new textbuf.Lines changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jul 22, 2024
1 parent 02a66d7 commit e25738a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion code/appbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Check failure on line 342 in code/appbar.go

View workflow job for this annotation

GitHub Actions / build

tv.Buffer.Highlighter undefined (type *texteditor.Buffer has no field or method Highlighter)
return
}
pfs := tv.Buffer.ParseState.Done()
Expand Down
8 changes: 3 additions & 5 deletions code/commandbufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 34 in code/commandbufs.go

View workflow job for this annotation

GitHub Actions / build

cannot use fileinfo.Bash (constant 18 of type fileinfo.Known) as string value in argument to buf.SetLanguage
return buf, true
}

Expand Down
20 changes: 8 additions & 12 deletions code/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -333,31 +333,27 @@ 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 {

Check failure on line 336 in code/editor.go

View workflow job for this annotation

GitHub Actions / build

invalid operation: cannot call non-function av.Buffer.NumLines (variable of type int)
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

Check failure on line 339 in code/editor.go

View workflow job for this annotation

GitHub Actions / build

invalid operation: cannot call non-function av.Buffer.NumLines (variable of type int)
reg := textbuf.NewRegion(0, 0, ll, av.Buffer.NumLines())

Check failure on line 340 in code/editor.go

View workflow job for this annotation

GitHub Actions / build

invalid operation: cannot call non-function av.Buffer.NumLines (variable of type int)
words, lines := av.Buffer.CountWordsLinesRegion(reg)

Check failure on line 341 in code/editor.go

View workflow job for this annotation

GitHub Actions / build

av.Buffer.CountWordsLinesRegion undefined (type *texteditor.Buffer has no field or method CountWordsLinesRegion)
return fmt.Sprintf("File: %s Words: %d Lines: %d\n", fsx.DirAndFile(string(av.Buffer.Filename)), words, lines)
}

// CountWordsRegion counts number of words (and lines) in selected region in file
// 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 {

Check failure on line 349 in code/editor.go

View workflow job for this annotation

GitHub Actions / build

invalid operation: cannot call non-function av.Buffer.NumLines (variable of type int)
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)
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions code/findpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions code/spellpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down Expand Up @@ -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++
Expand All @@ -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()
Expand Down Expand Up @@ -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--
}
Expand Down
4 changes: 2 additions & 2 deletions code/symbolspanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion mail/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Check failure on line 39 in mail/send.go

View workflow job for this annotation

GitHub Actions / build

cannot use fileinfo.Markdown (constant 58 of type fileinfo.Known) as string value in argument to ed.Buffer.SetLanguage
ed.Buffer.Options.LineNumbers = false
ed.Styler(func(s *styles.Style) {
s.SetMono(false)
Expand Down
5 changes: 3 additions & 2 deletions terminal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e25738a

Please sign in to comment.