Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in utf8 editing & set cursor #103

Closed
wants to merge 5 commits into from

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

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?

@@ -183,7 +205,7 @@ func (v *View) moveCursor(dx, dy int) {
if newX > len(line) {
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?


go 1.13

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

@@ -6,7 +6,6 @@ package gocui

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