mirror of https://github.com/lapce/lapce.git
scroll
This commit is contained in:
parent
b58c89035b
commit
b2807f20e5
|
@ -23,6 +23,7 @@ type Editor struct {
|
||||||
buffers map[string]*Buffer
|
buffers map[string]*Buffer
|
||||||
buffersRWMutex sync.RWMutex
|
buffersRWMutex sync.RWMutex
|
||||||
|
|
||||||
|
activeWin *Window
|
||||||
winIndex int
|
winIndex int
|
||||||
wins map[int]*Window
|
wins map[int]*Window
|
||||||
winsRWMutext sync.RWMutex
|
winsRWMutext sync.RWMutex
|
||||||
|
@ -73,7 +74,16 @@ func NewEditor() (*Editor, error) {
|
||||||
}
|
}
|
||||||
buffer.applyUpdate(u)
|
buffer.applyUpdate(u)
|
||||||
case *xi.ScrollTo:
|
case *xi.ScrollTo:
|
||||||
// e.view.scrollto(u.Col, u.Line)
|
if e.activeWin == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e.activeWin.buffer == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e.activeWin.buffer.xiView.ID != u.ViewID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.activeWin.scrollto(u.Col, u.Line)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
e.xi.HandleUpdate = e.handleUpdate
|
e.xi.HandleUpdate = e.handleUpdate
|
||||||
|
|
|
@ -114,23 +114,31 @@ func NewView(e *Editor) *View {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *View) scrollto(col, row int) {
|
func (v *View) scrollto(col, row int) {
|
||||||
if v.cursor == nil {
|
// if v.cursor == nil {
|
||||||
v.cursor = v.scence.AddRect2(
|
// v.cursor = v.scence.AddRect2(
|
||||||
0,
|
// 0,
|
||||||
0,
|
// 0,
|
||||||
|
// 1,
|
||||||
|
// v.font.lineHeight,
|
||||||
|
// gui.NewQPen(),
|
||||||
|
// gui.NewQBrush3(gui.NewQColor3(0, 0, 0, 255), core.Qt__SolidPattern))
|
||||||
|
// }
|
||||||
|
// if row >= len(v.lines) {
|
||||||
|
// row = len(v.lines) - 1
|
||||||
|
// }
|
||||||
|
// v.cursor.SetPos2(
|
||||||
|
// v.font.fontMetrics.Width(v.lines[row].text[:col])-0.5,
|
||||||
|
// )
|
||||||
|
// v.view.EnsureVisible3(v.cursor, 20, 20)
|
||||||
|
|
||||||
|
v.view.EnsureVisible2(
|
||||||
|
v.font.fontMetrics.Width(v.lines[row].text[:col])-0.5,
|
||||||
|
float64(row)*v.font.lineHeight,
|
||||||
1,
|
1,
|
||||||
v.font.lineHeight,
|
v.font.lineHeight,
|
||||||
gui.NewQPen(),
|
20,
|
||||||
gui.NewQBrush3(gui.NewQColor3(0, 0, 0, 255), core.Qt__SolidPattern))
|
20,
|
||||||
}
|
)
|
||||||
if row >= len(v.lines) {
|
|
||||||
row = len(v.lines) - 1
|
|
||||||
}
|
|
||||||
v.cursor.SetPos2(
|
|
||||||
v.font.fontMetrics.Width(v.lines[row].text[:col])-0.5,
|
|
||||||
float64(row)*v.font.lineHeight)
|
|
||||||
v.view.EnsureVisible3(v.cursor, 20, 20)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *View) height() int {
|
func (v *View) height() int {
|
||||||
|
|
|
@ -148,6 +148,7 @@ func (f *Frame) setFocus() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.win.view.SetFocus2()
|
f.win.view.SetFocus2()
|
||||||
|
f.editor.activeWin = f.win
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frame) close() *Frame {
|
func (f *Frame) close() *Frame {
|
||||||
|
@ -237,6 +238,7 @@ func NewWindow(editor *Editor, frame *Frame) *Window {
|
||||||
editor.winsRWMutext.Unlock()
|
editor.winsRWMutext.Unlock()
|
||||||
|
|
||||||
w.view.ConnectKeyPressEvent(func(event *gui.QKeyEvent) {
|
w.view.ConnectKeyPressEvent(func(event *gui.QKeyEvent) {
|
||||||
|
editor.activeWin = w
|
||||||
if w.buffer == nil {
|
if w.buffer == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -293,6 +295,7 @@ func NewWindow(editor *Editor, frame *Frame) *Window {
|
||||||
w.buffer.xiView.Insert(event.Text())
|
w.buffer.xiView.Insert(event.Text())
|
||||||
})
|
})
|
||||||
w.view.ConnectScrollContentsBy(func(dx, dy int) {
|
w.view.ConnectScrollContentsBy(func(dx, dy int) {
|
||||||
|
editor.activeWin = w
|
||||||
w.view.ScrollContentsByDefault(dx, dy)
|
w.view.ScrollContentsByDefault(dx, dy)
|
||||||
})
|
})
|
||||||
w.view.SetAlignment(core.Qt__AlignLeft | core.Qt__AlignTop)
|
w.view.SetAlignment(core.Qt__AlignLeft | core.Qt__AlignTop)
|
||||||
|
@ -305,3 +308,15 @@ func (w *Window) loadBuffer(buffer *Buffer) {
|
||||||
w.buffer = buffer
|
w.buffer = buffer
|
||||||
w.view.SetScene(buffer.scence)
|
w.view.SetScene(buffer.scence)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Window) scrollto(col, row int) {
|
||||||
|
b := w.buffer
|
||||||
|
w.view.EnsureVisible2(
|
||||||
|
b.font.fontMetrics.Width(b.lines[row].text[:col])-0.5,
|
||||||
|
float64(row)*b.font.lineHeight,
|
||||||
|
1,
|
||||||
|
b.font.lineHeight,
|
||||||
|
20,
|
||||||
|
20,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue