mirror of
https://github.com/jroimartin/gocui.git
synced 2025-05-01 22:17:55 +08:00
prevent race condition when deleting characters in editor
This commit is contained in:
parent
ee65bd542c
commit
de7bb5079f
15
edit.go
15
edit.go
@ -131,6 +131,9 @@ func (v *View) EditGotoToEndOfLine() {
|
||||
// EditDelete deletes a rune at the cursor position. back determines the
|
||||
// direction.
|
||||
func (v *View) EditDelete(back bool) {
|
||||
v.writeMutex.Lock()
|
||||
defer v.writeMutex.Unlock()
|
||||
|
||||
x, y := v.ox+v.cx, v.oy+v.cy
|
||||
if y < 0 {
|
||||
return
|
||||
@ -177,6 +180,9 @@ func (v *View) EditDelete(back bool) {
|
||||
|
||||
// EditNewLine inserts a new line under the cursor.
|
||||
func (v *View) EditNewLine() {
|
||||
v.writeMutex.Lock()
|
||||
defer v.writeMutex.Unlock()
|
||||
|
||||
v.breakLine(v.cx, v.cy)
|
||||
v.ox = 0
|
||||
v.cy = v.cy + 1
|
||||
@ -397,9 +403,6 @@ func (v *View) writeRune(x, y int, ch rune) error {
|
||||
// position corresponding to the point (x, y).
|
||||
// returns the amount of columns that where removed.
|
||||
func (v *View) deleteRune(x, y int) (int, error) {
|
||||
v.writeMutex.Lock()
|
||||
defer v.writeMutex.Unlock()
|
||||
|
||||
v.tainted = true
|
||||
|
||||
x, y, err := v.realPosition(x, y)
|
||||
@ -427,9 +430,6 @@ func (v *View) deleteRune(x, y int) (int, error) {
|
||||
|
||||
// mergeLines merges the lines "y" and "y+1" if possible.
|
||||
func (v *View) mergeLines(y int) error {
|
||||
v.writeMutex.Lock()
|
||||
defer v.writeMutex.Unlock()
|
||||
|
||||
v.clearViewLines()
|
||||
|
||||
_, y, err := v.realPosition(0, y)
|
||||
@ -451,9 +451,6 @@ func (v *View) mergeLines(y int) error {
|
||||
// breakLine breaks a line of the internal buffer at the position corresponding
|
||||
// to the point (x, y).
|
||||
func (v *View) breakLine(x, y int) error {
|
||||
v.writeMutex.Lock()
|
||||
defer v.writeMutex.Unlock()
|
||||
|
||||
v.tainted = true
|
||||
|
||||
x, y, err := v.realPosition(x, y)
|
||||
|
Loading…
x
Reference in New Issue
Block a user