Skip to content

Commit b4c11e9

Browse files
committed
fix: segmentation violation using GonvimWorkspaceNew command (#515)
1 parent d1c2563 commit b4c11e9

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

editor/cursor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (c *Cursor) updateCursorShape() {
468468
}
469469
if c.ws.palette != nil {
470470
if c.ws.palette.widget.IsVisible() {
471-
fontMetrics := gui.NewQFontMetricsF(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
471+
fontMetrics := gui.NewQFontMetricsF(editor.font.qfont)
472472
cellwidth = fontMetrics.HorizontalAdvance("w", -1)
473473
height = int(math.Ceil(fontMetrics.Height()))
474474
lineSpace = 0

editor/editor.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ type Editor struct {
118118
savedGeometry *core.QByteArray
119119
prefixToMapMetaKey string
120120
macAppArg string
121-
extFontFamily string
122121
configDir string
123122
homeDir string
124123
version string
@@ -138,7 +137,6 @@ type Editor struct {
138137
startuptime int64
139138
iconSize int
140139
height int
141-
extFontSize int
142140
notificationWidth int
143141
stopOnce sync.Once
144142
muMetaKey sync.Mutex
@@ -258,13 +256,11 @@ func InitEditor(options Options, args []string) {
258256

259257
// e.setAppDirPath(home)
260258

261-
e.extFontFamily = e.config.Editor.FontFamily
262-
e.extFontSize = e.config.Editor.FontSize
263259
e.fontCh = make(chan []*Font, 100)
264260
go func() {
265261
e.fontCh <- parseFont(
266-
editor.extFontFamily,
267-
editor.extFontSize,
262+
e.config.Editor.FontFamily,
263+
e.config.Editor.FontSize,
268264
e.config.Editor.FontWeight,
269265
e.config.Editor.FontStretch,
270266
e.config.Editor.Linespace,
@@ -828,10 +824,8 @@ func (e *Editor) setEnvironmentVariables() {
828824
}
829825

830826
func (e *Editor) initAppFont() {
831-
// e.extFontFamily = e.config.Editor.FontFamily
832-
// e.extFontSize = e.config.Editor.FontSize
833-
e.app.SetFont(gui.NewQFont2(e.extFontFamily, e.extFontSize, 1, false), "QWidget")
834-
e.app.SetFont(gui.NewQFont2(e.extFontFamily, e.extFontSize, 1, false), "QLabel")
827+
e.app.SetFont(e.font.qfont, "QWidget")
828+
e.app.SetFont(e.font.qfont, "QLabel")
835829

836830
e.putLog("initializing font")
837831
}
@@ -1116,6 +1110,8 @@ func (e *Editor) workspaceAdd() {
11161110

11171111
ws := newWorkspace()
11181112
ws.initUI()
1113+
ws.initFont()
1114+
11191115
ws.updateSize()
11201116
signal, redrawUpdates, guiUpdates, nvimCh, uiRemoteAttachedCh, _ := newNvim(ws.cols, ws.rows, e.ctx)
11211117
ws.registerSignal(signal, redrawUpdates, guiUpdates)

editor/notification.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func newNotification(l NotifyLevel, p int, message string, options ...NotifyOpti
7878

7979
label := widgets.NewQLabel(nil, 0)
8080
label.SetStyleSheet(" * {background-color: rgba(0, 0, 0, 0)}")
81-
size := int(editor.workspaces[editor.active].font.width * 1.33)
82-
label.SetFont(gui.NewQFont2(editor.extFontFamily, size, 1, false))
81+
// size := int(editor.workspaces[editor.active].font.width * 1.33)
82+
label.SetFont(editor.font.qfont)
8383
if utf8.RuneCountInString(message) > 50 {
8484
label.SetWordWrap(true)
8585
}
@@ -136,7 +136,7 @@ func newNotification(l NotifyLevel, p int, message string, options ...NotifyOpti
136136
if opt.text != "" {
137137
// * plugin install button
138138
buttonLabel := widgets.NewQLabel(nil, 0)
139-
buttonLabel.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize-1, 1, false))
139+
buttonLabel.SetFont(editor.font.qfont)
140140
buttonLabel.SetFixedHeight(28)
141141
buttonLabel.SetContentsMargins(10, 5, 10, 5)
142142
buttonLabel.SetAlignment(core.Qt__AlignCenter)

editor/palette.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,12 @@ func (p *Palette) redrawAllContentInWindows() {
335335
}
336336

337337
func (p *Palette) updateFont() {
338-
font := gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false)
339-
p.widget.SetFont(font)
340-
p.pattern.SetFont(font)
338+
p.widget.SetFont(editor.font.qfont)
339+
p.pattern.SetFont(editor.font.qfont)
341340
}
342341

343342
func (p *Palette) textLength() int {
344-
font := gui.NewQFontMetricsF(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
343+
font := gui.NewQFontMetricsF(editor.font.qfont)
345344
l := 0
346345
if p.isHTMLText {
347346
t := gui.NewQTextDocument(nil)
@@ -365,7 +364,7 @@ func (p *Palette) textLength() int {
365364
}
366365

367366
func (p *Palette) cursorPos(x int) int {
368-
font := gui.NewQFontMetricsF(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
367+
font := gui.NewQFontMetricsF(editor.font.qfont)
369368
l := 0
370369
if p.isHTMLText {
371370
t := gui.NewQTextDocument(nil)

editor/svg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func (e *Editor) getSvg(name string, color *RGBA) string {
328328
}
329329

330330
func (e *Editor) initSVGS() {
331-
e.iconSize = e.extFontSize * 11 / 9
331+
e.iconSize = e.config.Editor.FontSize * 11 / 9
332332
e.svgs = map[string]*SvgXML{}
333333

334334
e.svgs["default"] = &SvgXML{

editor/workspace.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func (ws *Workspace) registerSignal(signal *neovimSignal, redrawUpdates chan [][
373373
content.SetFocusPolicy(core.Qt__NoFocus)
374374
content.SetFrameShape(widgets.QFrame__NoFrame)
375375
content.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
376-
content.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
376+
content.SetFont(editor.font.qfont)
377377
content.SetIconSize(core.NewQSize2(editor.iconSize*3/4, editor.iconSize*3/4))
378378
editor.side.items[i].content = content
379379
editor.side.items[i].widget.Layout().AddWidget(content)
@@ -689,7 +689,7 @@ func (ws *Workspace) setCwd(cwd string) {
689689
}
690690

691691
sideItem.label.SetText(wse.cwdlabel)
692-
sideItem.label.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize-1, 1, false))
692+
sideItem.label.SetFont(editor.font.qfont)
693693
sideItem.cwdpath = path
694694
}
695695
}
@@ -788,6 +788,9 @@ func (ws *Workspace) updateSize() (windowWidth, windowHeight, cols, rows int) {
788788
screenWidth := width - scrollbarWidth - minimapWidth
789789
screenHeight := height - tablineHeight
790790

791+
if ws.screen.font == nil {
792+
fmt.Println("nil!")
793+
}
791794
rw := screenWidth - int(math.Ceil(float64(int(float64(screenWidth)/ws.screen.font.cellwidth))*ws.screen.font.cellwidth))
792795
rh := screenHeight % ws.screen.font.lineHeight
793796
screenWidth -= rw
@@ -2638,7 +2641,7 @@ func newWorkspaceSideItem() *WorkspaceSideItem {
26382641
content.SetFocusPolicy(core.Qt__NoFocus)
26392642
content.SetFrameShape(widgets.QFrame__NoFrame)
26402643
content.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
2641-
content.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
2644+
content.SetFont(editor.font.qfont)
26422645
content.SetIconSize(core.NewQSize2(editor.iconSize*3/4, editor.iconSize*3/4))
26432646

26442647
labelLayout.AddWidget(openIcon, 0, 0)

0 commit comments

Comments
 (0)