mirror of
https://github.com/bloeys/gopad.git
synced 2025-12-29 06:58:21 +00:00
Improve editing
This commit is contained in:
15
editor.go
15
editor.go
@ -162,6 +162,7 @@ func (e *Editor) Insert(posInfo *MousePosInfo, rs []rune) {
|
|||||||
if len(rs) == 0 {
|
if len(rs) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
e.IsModified = true
|
||||||
|
|
||||||
l := posInfo.Line
|
l := posInfo.Line
|
||||||
if len(l.chars) == 0 {
|
if len(l.chars) == 0 {
|
||||||
@ -199,6 +200,7 @@ func (e *Editor) Delete(posInfo *MousePosInfo, count int) {
|
|||||||
if len(l.chars) == 0 {
|
if len(l.chars) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
e.IsModified = true
|
||||||
|
|
||||||
if count >= len(l.chars) {
|
if count >= len(l.chars) {
|
||||||
l.chars = []rune{}
|
l.chars = []rune{}
|
||||||
@ -210,8 +212,21 @@ func (e *Editor) Delete(posInfo *MousePosInfo, count int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Count tabs that will be deleted
|
||||||
|
tabCount := 0
|
||||||
|
for i := charIndex - count + 1; i < charIndex+1; i++ {
|
||||||
|
if l.chars[i] == '\t' {
|
||||||
|
tabCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
l.chars = append(l.chars[:charIndex-count+1], l.chars[charIndex+1:]...)
|
l.chars = append(l.chars[:charIndex-count+1], l.chars[charIndex+1:]...)
|
||||||
|
|
||||||
|
if tabCount == 0 {
|
||||||
e.MoveMouseXByChars(-1, posInfo)
|
e.MoveMouseXByChars(-1, posInfo)
|
||||||
|
} else {
|
||||||
|
e.MoveMouseXByChars(-tabCount*settings.TabSize, posInfo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) MoveMouseXByChars(charCount int, posInfo *MousePosInfo) {
|
func (e *Editor) MoveMouseXByChars(charCount int, posInfo *MousePosInfo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user