mirror of https://github.com/lapce/lapce.git
split cursor
This commit is contained in:
parent
fa8af303be
commit
c2c501ebd9
|
@ -1,8 +1,17 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/dzhou121/xi-go/editor"
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
_ "net/http/pprof"
|
||||||
|
|
||||||
|
"github.com/dzhou121/xi-go/editor"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
go func() {
|
||||||
|
http.ListenAndServe("localhost:6020", nil)
|
||||||
|
}()
|
||||||
editor, err := editor.NewEditor()
|
editor, err := editor.NewEditor()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -111,6 +111,7 @@ func NewEditor() (*Editor, error) {
|
||||||
defer e.winsRWMutext.RUnlock()
|
defer e.winsRWMutext.RUnlock()
|
||||||
for _, win := range e.wins {
|
for _, win := range e.wins {
|
||||||
win.view.SetStyleSheet(scrollBarStyleSheet)
|
win.view.SetStyleSheet(scrollBarStyleSheet)
|
||||||
|
win.cline.SetStyleSheet(e.getClineStylesheet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -123,6 +124,15 @@ func NewEditor() (*Editor, error) {
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Editor) getClineStylesheet() string {
|
||||||
|
if e.theme == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
cline := e.theme.Theme.LineHighlight
|
||||||
|
styleSheet := fmt.Sprintf("background-color: rgba(%d, %d, %d, %f);", cline.R, cline.G, cline.B, float64(cline.A)/255)
|
||||||
|
return styleSheet
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Editor) getScrollbarStylesheet() string {
|
func (e *Editor) getScrollbarStylesheet() string {
|
||||||
bg := e.theme.Theme.Background
|
bg := e.theme.Theme.Background
|
||||||
guide := e.theme.Theme.LineHighlight
|
guide := e.theme.Theme.LineHighlight
|
||||||
|
@ -232,10 +242,8 @@ func (e *Editor) initMainWindow() {
|
||||||
editor: e,
|
editor: e,
|
||||||
}
|
}
|
||||||
e.topWin = NewWindow(e, e.topFrame)
|
e.topWin = NewWindow(e, e.topFrame)
|
||||||
e.topWin.view.Move2(0, 0)
|
|
||||||
e.topWin.view.Resize2(e.width, e.height)
|
|
||||||
e.topWin.loadBuffer(NewBuffer(e, "/Users/Lulu/xi-editor/rust/core-lib/src/rpc.rs"))
|
e.topWin.loadBuffer(NewBuffer(e, "/Users/Lulu/xi-editor/rust/core-lib/src/rpc.rs"))
|
||||||
e.topWin.setScroll()
|
e.equalWins()
|
||||||
|
|
||||||
e.cursor = widgets.NewQWidget(nil, 0)
|
e.cursor = widgets.NewQWidget(nil, 0)
|
||||||
e.cursor.Resize2(1, 20)
|
e.cursor.Resize2(1, 20)
|
||||||
|
@ -278,6 +286,9 @@ func (e *Editor) organizeWins() {
|
||||||
win.view.Move2(win.frame.x, win.frame.y)
|
win.view.Move2(win.frame.x, win.frame.y)
|
||||||
win.view.Hide()
|
win.view.Hide()
|
||||||
win.view.Show()
|
win.view.Show()
|
||||||
|
win.cline.Resize2(win.frame.width, int(win.buffer.font.lineHeight))
|
||||||
|
win.cline.Hide()
|
||||||
|
win.cline.Show()
|
||||||
win.setScroll()
|
win.setScroll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ func (f *Frame) split(vertical bool) {
|
||||||
win.editor.equalWins()
|
win.editor.equalWins()
|
||||||
newWin.view.HorizontalScrollBar().SetValue(win.view.HorizontalScrollBar().Value())
|
newWin.view.HorizontalScrollBar().SetValue(win.view.HorizontalScrollBar().Value())
|
||||||
newWin.view.VerticalScrollBar().SetValue(win.view.VerticalScrollBar().Value())
|
newWin.view.VerticalScrollBar().SetValue(win.view.VerticalScrollBar().Value())
|
||||||
|
newWin.scrollto(newWin.col, newWin.row)
|
||||||
f.setFocus()
|
f.setFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,8 +296,11 @@ type Window struct {
|
||||||
id int
|
id int
|
||||||
editor *Editor
|
editor *Editor
|
||||||
view *widgets.QGraphicsView
|
view *widgets.QGraphicsView
|
||||||
|
cline *widgets.QWidget
|
||||||
frame *Frame
|
frame *Frame
|
||||||
buffer *Buffer
|
buffer *Buffer
|
||||||
|
x float64
|
||||||
|
y float64
|
||||||
cursorX int
|
cursorX int
|
||||||
cursorY int
|
cursorY int
|
||||||
row int
|
row int
|
||||||
|
@ -313,7 +317,32 @@ func NewWindow(editor *Editor, frame *Frame) *Window {
|
||||||
editor: editor,
|
editor: editor,
|
||||||
frame: frame,
|
frame: frame,
|
||||||
view: widgets.NewQGraphicsView(nil),
|
view: widgets.NewQGraphicsView(nil),
|
||||||
|
cline: widgets.NewQWidget(nil, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.view.ConnectEventFilter(func(watched *core.QObject, event *core.QEvent) bool {
|
||||||
|
if event.Type() == core.QEvent__MouseButtonPress {
|
||||||
|
mousePress := gui.NewQMouseEventFromPointer(event.Pointer())
|
||||||
|
w.view.MousePressEvent(mousePress)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// else if event.Type() == core.QEvent__Wheel {
|
||||||
|
// wheelEvent := gui.NewQWheelEventFromPointer(event.Pointer())
|
||||||
|
// // delta := wheelEvent.PixelDelta()
|
||||||
|
// // w.view.ScrollContentsByDefault(delta.X(), delta.Y())
|
||||||
|
// // fmt.Println("scroll by", delta.X(), delta.Y())
|
||||||
|
// w.view.WheelEventDefault(wheelEvent)
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
return w.view.EventFilterDefault(watched, event)
|
||||||
|
})
|
||||||
|
w.cline.SetParent(w.view)
|
||||||
|
w.cline.SetStyleSheet(editor.getClineStylesheet())
|
||||||
|
w.cline.SetFocusPolicy(core.Qt__NoFocus)
|
||||||
|
w.cline.InstallEventFilter(w.view)
|
||||||
|
w.cline.ConnectWheelEvent(func(event *gui.QWheelEvent) {
|
||||||
|
w.view.WheelEventDefault(event)
|
||||||
|
})
|
||||||
frame.win = w
|
frame.win = w
|
||||||
editor.winIndex++
|
editor.winIndex++
|
||||||
editor.wins[w.id] = w
|
editor.wins[w.id] = w
|
||||||
|
@ -428,8 +457,20 @@ func (w *Window) update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Window) updateCursor() {
|
||||||
|
w.cursorX = int(w.x+0.5) - w.view.HorizontalScrollBar().Value()
|
||||||
|
w.cursorY = int(w.y+0.5) - w.view.VerticalScrollBar().Value()
|
||||||
|
cursor := w.editor.cursor
|
||||||
|
cursor.Move2(w.cursorX, w.cursorY)
|
||||||
|
cursor.Resize2(1, int(w.buffer.font.lineHeight+0.5))
|
||||||
|
cursor.Hide()
|
||||||
|
cursor.Show()
|
||||||
|
w.cline.Move2(0, w.cursorY)
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Window) setScroll() {
|
func (w *Window) setScroll() {
|
||||||
w.update()
|
w.update()
|
||||||
|
w.updateCursor()
|
||||||
w.buffer.xiView.Scroll(w.start, w.end)
|
w.buffer.xiView.Scroll(w.start, w.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,25 +481,17 @@ func (w *Window) loadBuffer(buffer *Buffer) {
|
||||||
|
|
||||||
func (w *Window) scrollto(col, row int) {
|
func (w *Window) scrollto(col, row int) {
|
||||||
b := w.buffer
|
b := w.buffer
|
||||||
x := b.font.fontMetrics.Width(b.lines[row].text[:col]) - 0.5
|
w.x = b.font.fontMetrics.Width(b.lines[row].text[:col]) - 0.5
|
||||||
y := float64(row) * b.font.lineHeight
|
w.y = float64(row) * b.font.lineHeight
|
||||||
w.view.EnsureVisible2(
|
w.view.EnsureVisible2(
|
||||||
x,
|
w.x,
|
||||||
y,
|
w.y,
|
||||||
1,
|
1,
|
||||||
b.font.lineHeight,
|
b.font.lineHeight,
|
||||||
20,
|
20,
|
||||||
20,
|
20,
|
||||||
)
|
)
|
||||||
x -= float64(w.view.HorizontalScrollBar().Value())
|
|
||||||
y -= float64(w.view.VerticalScrollBar().Value())
|
|
||||||
w.row = row
|
w.row = row
|
||||||
w.col = col
|
w.col = col
|
||||||
w.cursorX = int(x + 0.5)
|
w.updateCursor()
|
||||||
w.cursorY = int(y + 0.5)
|
|
||||||
cursor := w.editor.cursor
|
|
||||||
cursor.Move2(w.cursorX, w.cursorY)
|
|
||||||
cursor.Resize2(1, int(b.font.lineHeight+0.5))
|
|
||||||
cursor.Hide()
|
|
||||||
cursor.Show()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
@ -139,9 +138,9 @@ func (h *handler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("-------------------------")
|
// fmt.Println("-------------------------")
|
||||||
fmt.Println(req.Method)
|
// fmt.Println(req.Method)
|
||||||
fmt.Println(string(params))
|
// fmt.Println(string(params))
|
||||||
switch req.Method {
|
switch req.Method {
|
||||||
case "update":
|
case "update":
|
||||||
var notification UpdateNotification
|
var notification UpdateNotification
|
||||||
|
|
Loading…
Reference in New Issue