Skip to content

Fix bug in utf8 editing & set cursor#103

Closed
aynakeya wants to merge 5 commits intoawesome-gocui:masterfrom
aynakeya:master
Closed

Fix bug in utf8 editing & set cursor#103
aynakeya wants to merge 5 commits intoawesome-gocui:masterfrom
aynakeya:master

Conversation

@aynakeya
Copy link

@aynakeya aynakeya commented Nov 9, 2021

Fix problem with delete, insert, cursor move when editing utf8 runes.

Related: jroimartin#74 jesseduffield#10

@@ -1,10 +1,9 @@
module github.com/awesome-gocui/gocui
module github.com/aynakeya/gocui
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you restore this change?

if dy == 0 && newY+1 < len(v.lines) {
newY++
// line = v.lines[newY] // Uncomment if adding code that uses line
//line = v.lines[newY] // Uncomment if adding code that uses line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you restore this change?

Comment on lines +159 to +181
newX, newY := v.cx+dx, v.cy+dy
// If newY is more than all lines set it to the last line
if newY >= len(v.lines) {
newY = len(v.lines) - 1
}
if newY < 0 {
newY = 0
}
if dx != 0 {
line := v.lines[newY]
col := 0
for index, _ := range line {
col += runewidth.RuneWidth(line[index].chr)
if newX <= col && dx >= 0 {
dx = runewidth.RuneWidth(line[index].chr)
break
}
if newX < col && dx < 0 {
dx = -runewidth.RuneWidth(line[index].chr)
break
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to what this is doing?

Comment on lines +286 to +292
for i := 1; i < w; i++ {
v.lines[y][x+i] = cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: '\x00',
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to what this is doing?

require (
github.com/gdamore/tcell/v2 v2.0.0
github.com/mattn/go-runewidth v0.0.9
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this change


import (
"errors"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you restore this change

}
}
v.moveCursor(dx, dy)
v.gui.userEvents <- userEvent{func(g *Gui) error { return nil }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this line?

@aynakeya
Copy link
Author

aynakeya commented Nov 9, 2021

sry i forget to create a new branch. gonna create a new pull request again.

@aynakeya aynakeya closed this Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants