From bc3c8eaf74d07ef010270c883198e530d23c2e5a Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 12 Jun 2017 15:59:00 -0400 Subject: [PATCH] Use terminal cursor for the base cursor If all cursors fake then that breaks support for things like inserting japanese characters nicely, so fake cursors are now only used as extra cursors. --- cmd/micro/messenger.go | 6 +++--- cmd/micro/view.go | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/micro/messenger.go b/cmd/micro/messenger.go index 6c212910..3fda5368 100644 --- a/cmd/micro/messenger.go +++ b/cmd/micro/messenger.go @@ -153,7 +153,7 @@ func (m *Messenger) YesNoPrompt(prompt string) (bool, bool) { for { m.Clear() m.Display() - ShowCursor(Count(m.message), h-1) + screen.ShowCursor(Count(m.message), h-1) screen.Show() event := <-events @@ -190,7 +190,7 @@ func (m *Messenger) LetterPrompt(prompt string, responses ...rune) (rune, bool) for { m.Clear() m.Display() - ShowCursor(Count(m.message), h-1) + screen.ShowCursor(Count(m.message), h-1) screen.Show() event := <-events @@ -470,7 +470,7 @@ func (m *Messenger) Display() { } if m.hasPrompt { - ShowCursor(Count(m.message)+m.cursorx, h-1) + screen.ShowCursor(Count(m.message)+m.cursorx, h-1) screen.Show() } } diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 3813f8d9..1162b461 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -865,12 +865,12 @@ func (v *View) DisplayView() { screen.SetContent(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, char.drawChar, nil, lineStyle) - for _, c := range v.Buf.cursors { + for i, c := range v.Buf.cursors { v.Cursor = c if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() && - v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X && !cursorSet { - ShowCursor(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y) - // cursorSet = true + v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X && (!cursorSet || i != 0) { + ShowMultiCursor(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, i) + cursorSet = true } } v.Cursor = &v.Buf.Cursor @@ -885,11 +885,11 @@ func (v *View) DisplayView() { var cx, cy int if lastChar != nil { lastX = xOffset + lastChar.visualLoc.X + lastChar.width - for _, c := range v.Buf.cursors { + for i, c := range v.Buf.cursors { v.Cursor = c if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() && v.Cursor.Y == lastChar.realLoc.Y && v.Cursor.X == lastChar.realLoc.X+1 { - ShowCursor(lastX, yOffset+lastChar.visualLoc.Y) + ShowMultiCursor(lastX, yOffset+lastChar.visualLoc.Y, i) cx, cy = lastX, yOffset+lastChar.visualLoc.Y } } @@ -897,11 +897,11 @@ func (v *View) DisplayView() { realLoc = Loc{lastChar.realLoc.X + 1, realLineN} visualLoc = Loc{lastX - xOffset, lastChar.visualLoc.Y} } else if len(line) == 0 { - for _, c := range v.Buf.cursors { + for i, c := range v.Buf.cursors { v.Cursor = c if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() && v.Cursor.Y == realLineN { - ShowCursor(xOffset, yOffset+visualLineN) + ShowMultiCursor(xOffset, yOffset+visualLineN, i) cx, cy = xOffset, yOffset+visualLineN } } @@ -947,9 +947,13 @@ func (v *View) DisplayView() { } } -func ShowCursor(x, y int) { - r, _, _, _ := screen.GetContent(x, y) - screen.SetContent(x, y, r, nil, defStyle.Reverse(true)) +func ShowMultiCursor(x, y, i int) { + if i == 0 { + screen.ShowCursor(x, y) + } else { + r, _, _, _ := screen.GetContent(x, y) + screen.SetContent(x, y, r, nil, defStyle.Reverse(true)) + } } // Display renders the view, the cursor, and statusline