-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
628 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package editor | ||
|
||
import ( | ||
"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{}) { | ||
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 { | ||
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 { | ||
continue | ||
} | ||
|
||
win.storeGuiwidget(gw.id, gw) | ||
cell := win.content[row][col] | ||
if cell != nil { | ||
cell.decal = &Decal{ | ||
exists: true, | ||
markid: markid, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
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 initGuiwidget() *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{}) { | ||
for _, update := range updates { | ||
a := update.(map[string]interface{}) | ||
|
||
idITF, ok := a["id"] | ||
if !ok { | ||
continue | ||
} | ||
id := util.ReflectToInt(idITF) | ||
|
||
var g *Guiwidget | ||
if g, ok = w.getGuiwidgetFromResID(id); !ok { | ||
g = initGuiwidget() | ||
w.storeGuiwidget(id, g) | ||
g.s = w.screen | ||
} | ||
|
||
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.text = 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{}) { | ||
var markid, resid, width, height int | ||
for _, update := range updates { | ||
a := update.(map[string]interface{}) | ||
|
||
buf, ok := a["buf"] | ||
if !ok { | ||
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 { | ||
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 = initGuiwidget() | ||
w.storeGuiwidget(resid, g) | ||
g.s = w.screen | ||
} | ||
|
||
g.winid = winid | ||
g.markID = markid | ||
g.width = width | ||
g.height = height | ||
switch g.mime { | ||
case "text/plain": | ||
baseFont := g.s.ws.font | ||
g.font = initFontNew( | ||
baseFont.fontNew.Family(), | ||
float64(g.height*baseFont.height)*0.8, | ||
0, | ||
0, | ||
) | ||
default: | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.