MCPcopy Create free account
hub / github.com/cogentcore/core / replaceText

Method replaceText

texteditor/text/lines.go:1068–1079  ·  view source on GitHub ↗

ReplaceText does DeleteText for given region, and then InsertText at given position (typically same as delSt but not necessarily). 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

(delSt, delEd, insPos lexer.Pos, insTxt string, matchCase bool)

Source from the content-addressed store, hash-verified

1066// returns the Edit for the inserted text.
1067// An Undo record is automatically saved depending on Undo.Off setting.
1068func (ls *Lines) replaceText(delSt, delEd, insPos lexer.Pos, insTxt string, matchCase bool) *Edit {
1069 if matchCase {
1070 red := ls.region(delSt, delEd)
1071 cur := string(red.ToBytes())
1072 insTxt = lexer.MatchCase(cur, insTxt)
1073 }
1074 if len(insTxt) > 0 {
1075 ls.deleteText(delSt, delEd)
1076 return ls.insertText(insPos, []byte(insTxt))
1077 }
1078 return ls.deleteText(delSt, delEd)
1079}
1080
1081/////////////////////////////////////////////////////////////////////////////
1082// Undo

Callers 4

ReplaceTextMethod · 0.95
joinParaLinesMethod · 0.95
tabsToSpacesLineMethod · 0.95
spacesToTabsLineMethod · 0.95

Calls 5

regionMethod · 0.95
deleteTextMethod · 0.95
insertTextMethod · 0.95
MatchCaseFunction · 0.92
ToBytesMethod · 0.80

Tested by

no test coverage detected