fix: segmentation violation using GonvimWorkspaceNew command (#515)

This commit is contained in:
akiyosi 2024-01-12 13:29:26 +09:00
parent d1c2563e3b
commit b4c11e98f3
6 changed files with 21 additions and 23 deletions

View file

@ -468,7 +468,7 @@ func (c *Cursor) updateCursorShape() {
}
if c.ws.palette != nil {
if c.ws.palette.widget.IsVisible() {
fontMetrics := gui.NewQFontMetricsF(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
fontMetrics := gui.NewQFontMetricsF(editor.font.qfont)
cellwidth = fontMetrics.HorizontalAdvance("w", -1)
height = int(math.Ceil(fontMetrics.Height()))
lineSpace = 0

View file

@ -118,7 +118,6 @@ type Editor struct {
savedGeometry *core.QByteArray
prefixToMapMetaKey string
macAppArg string
extFontFamily string
configDir string
homeDir string
version string
@ -138,7 +137,6 @@ type Editor struct {
startuptime int64
iconSize int
height int
extFontSize int
notificationWidth int
stopOnce sync.Once
muMetaKey sync.Mutex
@ -258,13 +256,11 @@ func InitEditor(options Options, args []string) {
// e.setAppDirPath(home)
e.extFontFamily = e.config.Editor.FontFamily
e.extFontSize = e.config.Editor.FontSize
e.fontCh = make(chan []*Font, 100)
go func() {
e.fontCh <- parseFont(
editor.extFontFamily,
editor.extFontSize,
e.config.Editor.FontFamily,
e.config.Editor.FontSize,
e.config.Editor.FontWeight,
e.config.Editor.FontStretch,
e.config.Editor.Linespace,
@ -828,10 +824,8 @@ func (e *Editor) setEnvironmentVariables() {
}
func (e *Editor) initAppFont() {
// e.extFontFamily = e.config.Editor.FontFamily
// e.extFontSize = e.config.Editor.FontSize
e.app.SetFont(gui.NewQFont2(e.extFontFamily, e.extFontSize, 1, false), "QWidget")
e.app.SetFont(gui.NewQFont2(e.extFontFamily, e.extFontSize, 1, false), "QLabel")
e.app.SetFont(e.font.qfont, "QWidget")
e.app.SetFont(e.font.qfont, "QLabel")
e.putLog("initializing font")
}
@ -1116,6 +1110,8 @@ func (e *Editor) workspaceAdd() {
ws := newWorkspace()
ws.initUI()
ws.initFont()
ws.updateSize()
signal, redrawUpdates, guiUpdates, nvimCh, uiRemoteAttachedCh, _ := newNvim(ws.cols, ws.rows, e.ctx)
ws.registerSignal(signal, redrawUpdates, guiUpdates)

View file

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

View file

@ -335,13 +335,12 @@ func (p *Palette) redrawAllContentInWindows() {
}
func (p *Palette) updateFont() {
font := gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false)
p.widget.SetFont(font)
p.pattern.SetFont(font)
p.widget.SetFont(editor.font.qfont)
p.pattern.SetFont(editor.font.qfont)
}
func (p *Palette) textLength() int {
font := gui.NewQFontMetricsF(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
font := gui.NewQFontMetricsF(editor.font.qfont)
l := 0
if p.isHTMLText {
t := gui.NewQTextDocument(nil)
@ -365,7 +364,7 @@ func (p *Palette) textLength() int {
}
func (p *Palette) cursorPos(x int) int {
font := gui.NewQFontMetricsF(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
font := gui.NewQFontMetricsF(editor.font.qfont)
l := 0
if p.isHTMLText {
t := gui.NewQTextDocument(nil)

View file

@ -328,7 +328,7 @@ func (e *Editor) getSvg(name string, color *RGBA) string {
}
func (e *Editor) initSVGS() {
e.iconSize = e.extFontSize * 11 / 9
e.iconSize = e.config.Editor.FontSize * 11 / 9
e.svgs = map[string]*SvgXML{}
e.svgs["default"] = &SvgXML{

View file

@ -373,7 +373,7 @@ func (ws *Workspace) registerSignal(signal *neovimSignal, redrawUpdates chan [][
content.SetFocusPolicy(core.Qt__NoFocus)
content.SetFrameShape(widgets.QFrame__NoFrame)
content.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
content.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
content.SetFont(editor.font.qfont)
content.SetIconSize(core.NewQSize2(editor.iconSize*3/4, editor.iconSize*3/4))
editor.side.items[i].content = content
editor.side.items[i].widget.Layout().AddWidget(content)
@ -689,7 +689,7 @@ func (ws *Workspace) setCwd(cwd string) {
}
sideItem.label.SetText(wse.cwdlabel)
sideItem.label.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize-1, 1, false))
sideItem.label.SetFont(editor.font.qfont)
sideItem.cwdpath = path
}
}
@ -788,6 +788,9 @@ func (ws *Workspace) updateSize() (windowWidth, windowHeight, cols, rows int) {
screenWidth := width - scrollbarWidth - minimapWidth
screenHeight := height - tablineHeight
if ws.screen.font == nil {
fmt.Println("nil!")
}
rw := screenWidth - int(math.Ceil(float64(int(float64(screenWidth)/ws.screen.font.cellwidth))*ws.screen.font.cellwidth))
rh := screenHeight % ws.screen.font.lineHeight
screenWidth -= rw
@ -2638,7 +2641,7 @@ func newWorkspaceSideItem() *WorkspaceSideItem {
content.SetFocusPolicy(core.Qt__NoFocus)
content.SetFrameShape(widgets.QFrame__NoFrame)
content.SetHorizontalScrollBarPolicy(core.Qt__ScrollBarAlwaysOff)
content.SetFont(gui.NewQFont2(editor.extFontFamily, editor.extFontSize, 1, false))
content.SetFont(editor.font.qfont)
content.SetIconSize(core.NewQSize2(editor.iconSize*3/4, editor.iconSize*3/4))
labelLayout.AddWidget(openIcon, 0, 0)