Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions editor/extmarks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package editor

import (
"fmt"

"github.com/akiyosi/goneovim/util"
"github.com/neovim/go-client/nvim"
)

// windowExtmarks is
// ["win_extmark", grid, win, ns_id, mark_id, row, col]
// Updates the position of an extmark which is currently visible in a
// window. Only emitted if the mark has the `ui_watched` attribute.
func (ws *Workspace) windowExtmarks(args []interface{}) {
fmt.Println("win_extmark event")
for _, e := range args {
arg := e.([]interface{})
grid := util.ReflectToInt(arg[0])
winid := (arg[1]).(nvim.Window)
_ = util.ReflectToInt(arg[2])
markid := util.ReflectToInt(arg[3])
row := util.ReflectToInt(arg[4])
col := util.ReflectToInt(arg[5])

win, ok := ws.screen.getWindow(grid)
if !ok {
fmt.Println("debug 21:: continue")
return
}

var gw *Guiwidget
ws.guiWidgets.Range(func(_, gITF interface{}) bool {
g := gITF.(*Guiwidget)
if g == nil {
return true
}
if markid == g.markID && g.winid == winid {
gw = g
return false
}
return true
})
if gw == nil {
fmt.Println("debug 22:: continue")
continue
}

win.storeGuiwidget(gw.id, gw)
cell := win.content[row][col]
if cell != nil {
cell.decal = &Decal{
exists: true,
markid: markid,
}
}

win.hasExtmarks = true
// if gw.width == 0 && gw.height == 0 {
// continue
// }
// fmt.Println("debug::", "gridid", win.grid, gw.markID, "text", gw.text, "row,col:", row, col, "width, height:", gw.width, gw.height)
// win.queueRedraw(row, col, gw.width+1, gw.height)
// for i := row; i <= row+gw.height; i++ {
// if i >= len(win.contentMask) {
// continue
// }
// for j := col; j <= col+gw.height; j++ {
// if j >= len(win.contentMask[i]) {
// continue
// }
// win.contentMask[i][j] = true
// }
// }
// win.update()
}
}
174 changes: 174 additions & 0 deletions editor/guiwidget.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package editor

import (
"fmt"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"strconv"
"time"

"github.com/akiyosi/goneovim/util"
"github.com/neovim/go-client/nvim"
"github.com/therecipe/qt/core"
)

type Guiwidget struct {
Tooltip

raw string
data *core.QByteArray
mime string
width int
height int
id int
markID int
winid nvim.Window
}

func newGuiwidget() *Guiwidget {
guiwidget := NewGuiwidget(nil, 0)
guiwidget.data = nil
guiwidget.width = 0
guiwidget.height = 0
guiwidget.mime = ""
guiwidget.id = 0
guiwidget.ConnectPaintEvent(guiwidget.paint)

return guiwidget
}

// GuiWidgetPut pushes visual resource data to the front-end
func (w *Workspace) handleRPCGuiwidgetput(updates []interface{}) {
fmt.Println("put guiwidgets")
for _, update := range updates {
a := update.(map[string]interface{})

idITF, ok := a["id"]
if !ok {
fmt.Println("debug 7:: continue")
continue
}
id := util.ReflectToInt(idITF)

var g *Guiwidget
if g, ok = w.getGuiwidgetFromResID(id); !ok {
g = newGuiwidget()
w.storeGuiwidget(id, g)
g.s = w.screen
g.setFont(g.s.font)
}

g.id = id

mime, ok := a["mime"]
if ok {
g.mime = mime.(string)
}

data, ok := a["data"]
if ok {
s := data.(string)

switch mime {
case "text/plain":
g.updateText(g.s.hlAttrDef[0], s)

case "image/svg",
"image/svg+xml",
"image/png",
"image/gif",
"image/jpeg",
"image/*":
g.raw = s
default:
}
}
}
}

// GuiWidgetUpdateView sends a list of "placements".
// A placement associates an extmark with a resource id, and provides
// display options for a widget (width, height, mouse events etc.).
func (w *Workspace) handleRPCGuiwidgetview(updates []interface{}) {
fmt.Println("view guiwidgets")
var markid, resid, width, height int
for _, update := range updates {
a := update.(map[string]interface{})

buf, ok := a["buf"]
if !ok {
fmt.Println("debug 10:: continue")
continue
}

errChan := make(chan error, 60)
var err error
var outstr string
go func() {
outstr, err = w.nvim.CommandOutput(
fmt.Sprintf("echo bufwinid(%d)", util.ReflectToInt(buf)),
)
errChan <- err
}()
select {
case <-errChan:
case <-time.After(40 * time.Millisecond):
}

out, _ := strconv.Atoi(outstr)
winid := (nvim.Window)(out)

widgets, ok := a["widgets"]
if !ok {
fmt.Println("debug 11:: continue")
continue
}
for _, e := range widgets.([]interface{}) {
for k, ee := range e.([]interface{}) {
if k == 0 {
markid = util.ReflectToInt(ee)
} else if k == 1 {
resid = util.ReflectToInt(ee)
} else if k == 2 {
width = util.ReflectToInt(ee)
} else if k == 3 {
height = util.ReflectToInt(ee)
}
if k >= 4 {
}
}

var g *Guiwidget
if g, ok = w.getGuiwidgetFromResID(resid); !ok {
g = newGuiwidget()
w.storeGuiwidget(resid, g)
g.s = w.screen
g.setFont(g.s.font)
}

g.winid = winid
g.markID = markid
g.width = width
g.height = height

switch g.mime {
case "text/plain":
baseFont := g.s.ws.font
g.setFont(
// Set font adjusted to widgets height
initFontNew(
baseFont.fontNew.Family(),
float64(baseFont.height*g.height)*0.7,
0,
0,
),
)
default:
}

}

}

}
2 changes: 1 addition & 1 deletion editor/imetooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (i *IMETooltip) updateVirtualCursorPos() {
i.cursorVisualPos = int(x)
return
}
x += chunk.width
x += float64(chunk.scale) * i.font.cellwidth
k++
}
}
Expand Down
5 changes: 5 additions & 0 deletions editor/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,8 @@ func (s *Screen) detectCoveredCellInGlobalgrid() {
}

func (s *Screen) update() {
// shownMarks := []int{}

s.windows.Range(func(grid, winITF interface{}) bool {
win := winITF.(*Window)
// if grid is dirty, we remove this grid
Expand All @@ -1414,6 +1416,9 @@ func (s *Screen) update() {
win.fill()
}
win.update()

// shownMarksWin := win.updateExtMarks()
// shownMarks = append(shownMarks, shownMarksWin...)
}

return true
Expand Down
40 changes: 20 additions & 20 deletions editor/screen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ func TestWindow_updateLine(t *testing.T) {
},
},
[]Cell{
Cell{hldef[7], "~", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[7], "~", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
},
},
{
Expand All @@ -254,11 +254,11 @@ func TestWindow_updateLine(t *testing.T) {
},
},
[]Cell{
Cell{hldef[7], "~", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[6], "*", true, false},
Cell{hldef[6], "*", true, false},
Cell{hldef[7], "~", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[6], "*", true, false, nil},
Cell{hldef[6], "*", true, false, nil},
},
},
{
Expand All @@ -282,11 +282,11 @@ func TestWindow_updateLine(t *testing.T) {
},
},
[]Cell{
Cell{hldef[7], "~", true, false},
Cell{hldef[6], "@", true, false},
Cell{hldef[6], "v", true, false},
Cell{hldef[6], "i", true, false},
Cell{hldef[6], "m", true, false},
Cell{hldef[7], "~", true, false, nil},
Cell{hldef[6], "@", true, false, nil},
Cell{hldef[6], "v", true, false, nil},
Cell{hldef[6], "i", true, false, nil},
Cell{hldef[6], "m", true, false, nil},
},
},
{
Expand All @@ -308,11 +308,11 @@ func TestWindow_updateLine(t *testing.T) {
},
},
[]Cell{
Cell{hldef[7], " ", true, false},
Cell{hldef[7], " ", true, false},
Cell{hldef[7], "J", true, false},
Cell{hldef[6], "i", true, false},
Cell{hldef[6], "m", true, false},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[7], " ", true, false, nil},
Cell{hldef[7], "J", true, false, nil},
Cell{hldef[6], "i", true, false, nil},
Cell{hldef[6], "m", true, false, nil},
},
},
}
Expand Down
Loading