Skip to content

Commit 9a8e0af

Browse files
committed
[WIP] Proportional font: minor changes + fixes
+ rebase to master + add function getFontMetrics + use a single map in `refreshLinesPixels`, using struct as keys + apply akiyosi#591 (comment) + apply akiyosi#591 (comment) + `xPixelIndexes` is now of type `float64` + fix index out of range + fix cursor width in insert mode when completion windows pops up + fix background/decoration + fix visual mode wrap (background) + fix gridFontAutomaticHeight for autocmd + fix floating window position + fix character width, see: akiyosi#591 (comment)
1 parent 2ad0e14 commit 9a8e0af

File tree

7 files changed

+328
-299
lines changed

7 files changed

+328
-299
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,11 @@ jobs:
368368
fetch-depth: 0
369369
path: ${{ env.GOPATH }}\src\github.com\${{ github.repository }}
370370

371-
372371
- name: Get Qt binding for Go
373372
shell: msys2 {0}
374373
run: |
375374
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
376-
cd /c/a/goneovim/goneovim//src/github.com/${{ github.repository }}
375+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
377376
go get -v github.com/akiyosi/qt
378377
go get github.com/akiyosi/qt/internal/cmd@v0.0.0-20240304155940-b43fff373ad5
379378
go get github.com/akiyosi/qt/internal/binding/files/docs/5.12.0
@@ -396,21 +395,21 @@ jobs:
396395
shell: msys2 {0}
397396
run: |
398397
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
399-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
398+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
400399
$(go env GOPATH)/bin/qtsetup -test=false
401400
402401
- name: Get dependencies
403402
shell: msys2 {0}
404403
run: |
405404
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
406-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
405+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
407406
make deps
408407
409408
- name: Test
410409
shell: msys2 {0}
411410
run: |
412411
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
413-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
412+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
414413
make test
415414
416415
@@ -471,7 +470,7 @@ jobs:
471470
shell: msys2 {0}
472471
run: |
473472
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
474-
cd /c/a/goneovim/goneovim//src/github.com/${{ github.repository }}
473+
cd /d/a/goneovim/goneovim//src/github.com/${{ github.repository }}
475474
go get -v github.com/akiyosi/qt
476475
go get github.com/akiyosi/qt/internal/cmd@v0.0.0-20240304155940-b43fff373ad5
477476
go get github.com/akiyosi/qt/internal/binding/files/docs/5.12.0
@@ -486,7 +485,7 @@ jobs:
486485
shell: msys2 {0}
487486
run: |
488487
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
489-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
488+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
490489
make deps
491490
492491
### https://github.com/therecipe/qt/issues/657
@@ -501,7 +500,7 @@ jobs:
501500
shell: msys2 {0}
502501
run: |
503502
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
504-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
503+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
505504
$(go env GOPATH)/bin/qtmoc desktop ./cmd/goneovim
506505
go generate
507506
$(go env GOPATH)/bin/qtdeploy build desktop ./cmd/goneovim
@@ -510,15 +509,15 @@ jobs:
510509
- name: Rename
511510
shell: msys2 {0}
512511
run: |
513-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}/cmd/goneovim/deploy
512+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}/cmd/goneovim/deploy
514513
mv windows goneovim-windows
515514
# zip -r goneovim-windows.zip goneovim-windows
516515

517516
- name: Upload for windows
518517
uses: actions/upload-artifact@v4
519518
with:
520519
name: goneovim-windows
521-
path: C:/a/goneovim/goneovim/src/github.com/${{ github.repository }}/cmd/goneovim/deploy
520+
path: D:/a/goneovim/goneovim/src/github.com/${{ github.repository }}/cmd/goneovim/deploy
522521

523522

524523
# test-and-build-windows-msvc:

.github/workflows/release.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ jobs:
391391
shell: msys2 {0}
392392
run: |
393393
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
394-
cd /c/a/goneovim/goneovim//src/github.com/${{ github.repository }}
394+
cd /d/a/goneovim/goneovim//src/github.com/${{ github.repository }}
395395
go get -v github.com/akiyosi/qt
396396
go get github.com/akiyosi/qt/internal/cmd@v0.0.0-20240304155940-b43fff373ad5
397397
go get github.com/akiyosi/qt/internal/binding/files/docs/5.12.0
@@ -406,7 +406,7 @@ jobs:
406406
shell: msys2 {0}
407407
run: |
408408
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
409-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
409+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
410410
make deps
411411
412412
- name: Retrieve version
@@ -419,7 +419,7 @@ jobs:
419419
shell: msys2 {0}
420420
run: |
421421
export PATH=/c/hostedtoolcache/windows/go/${{ matrix.go-version }}/x64/bin/:$PATH
422-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}
422+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}
423423
$(go env GOPATH)/bin/qtmoc desktop ./cmd/goneovim
424424
go generate
425425
$(go env GOPATH)/bin/qtdeploy build desktop ./cmd/goneovim
@@ -435,7 +435,7 @@ jobs:
435435
- name: Archive
436436
shell: msys2 {0}
437437
run: |
438-
cd /c/a/goneovim/goneovim/src/github.com/${{ github.repository }}/cmd/goneovim/deploy
438+
cd /d/a/goneovim/goneovim/src/github.com/${{ github.repository }}/cmd/goneovim/deploy
439439
mv windows ${{ env.ARCHIVE_NAME }}
440440
zip -r ${{ env.ARCHIVE_NAME }}.zip ${{ env.ARCHIVE_NAME }}
441441

editor/cursor.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (c *Cursor) drawForeground(p *gui.QPainter, sx, sy, dx, dy float64, text st
165165
charCache := *c.charCache
166166
imagev, err := charCache.get(HlTextKey{
167167
text: text,
168-
fg: c.fg,
168+
fg: *(c.fg),
169169
italic: false,
170170
bold: false,
171171
})
@@ -267,7 +267,7 @@ func (c *Cursor) setCharCache(text string, fg *RGBA, image *gui.QImage) {
267267
c.charCache.set(
268268
HlTextKey{
269269
text: text,
270-
fg: c.fg,
270+
fg: *(c.fg),
271271
italic: false,
272272
bold: false,
273273
},
@@ -505,12 +505,13 @@ func (c *Cursor) updateCursorShape(win *Window) {
505505
}
506506
case "vertical":
507507
c.isTextDraw = true
508-
if (c.font == nil || !c.font.proportional) {
508+
c.horizontalShift = 0
509+
font := win.font
510+
if font == nil || !font.proportional {
509511
width = int(math.Ceil(float64(width) * p))
510512
} else {
511-
width = int(c.font.cellwidth) / 10
513+
width = int(font.cellwidth) / 10
512514
}
513-
c.horizontalShift = 0
514515
default:
515516
c.isTextDraw = true
516517
c.horizontalShift = 0

editor/editor.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package editor
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"log"
88
"os"
99
"os/exec"
@@ -867,31 +867,34 @@ func (e *Editor) setEnvironmentVariables() {
867867
}
868868

869869
// If the OS is MacOS and the application is launched from an .app
870-
if runtime.GOOS == "darwin" && e.ppid == 1 {
870+
if runtime.GOOS == "darwin" && os.Getenv("TERM") == "" {
871871
shell := os.Getenv("SHELL")
872872
if shell == "" {
873-
shell = os.Getenv("/bin/bash")
873+
shell = "/bin/zsh" // fallback
874874
}
875-
cmd := exec.Command(shell, "-l", "-c", "env", "-i")
876-
// cmd := exec.Command("printenv")
875+
876+
cmd := exec.Command(shell, "-l", "-c", "env")
877877
stdout, err := cmd.StdoutPipe()
878878
if err != nil {
879879
e.putLog(err)
880880
return
881881
}
882+
882883
if err := cmd.Start(); err != nil {
883884
e.putLog(err)
884885
return
885886
}
886-
output, err := ioutil.ReadAll(stdout)
887+
888+
output, err := io.ReadAll(stdout)
889+
stdout.Close()
887890
if err != nil {
888891
e.putLog(err)
889-
stdout.Close()
890892
return
891893
}
892-
for _, b := range strings.Split(string(output), "\n") {
893-
splits := strings.SplitN(b, "=", 2)
894-
if len(splits) > 1 {
894+
895+
for _, line := range strings.Split(string(output), "\n") {
896+
splits := strings.SplitN(line, "=", 2)
897+
if len(splits) == 2 {
895898
_ = os.Setenv(splits[0], splits[1])
896899
}
897900
}
@@ -1100,11 +1103,18 @@ func (e *Editor) setWindowSizeFromOpts() {
11001103
func (e *Editor) setWindowSize(s string) (int, int) {
11011104
var width, height int
11021105
var err error
1103-
width, err = strconv.Atoi(strings.SplitN(s, "x", 2)[0])
1106+
1107+
parsed_s := strings.SplitN(s, "x", 2)
1108+
if len(parsed_s) != 2 {
1109+
// TODO: Error message to user?
1110+
return 40, 30
1111+
}
1112+
1113+
width, err = strconv.Atoi(parsed_s[0])
11041114
if err != nil || width < 40 {
11051115
width = 40
11061116
}
1107-
height, err = strconv.Atoi(strings.SplitN(s, "x", 2)[1])
1117+
height, err = strconv.Atoi(parsed_s[1])
11081118
if err != nil || height < 30 {
11091119
height = 30
11101120
}

editor/screen.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var globalOrder int
2323
// Screen is the main editor area
2424
type Screen struct {
2525
cache Cache
26+
bgcache Cache
2627
tooltip *IMETooltip
2728
font *Font
2829
fallbackfonts []*Font
@@ -57,6 +58,7 @@ func newScreen() *Screen {
5758
cursor: [2]int{0, 0},
5859
highlightGroup: make(map[string]int),
5960
cache: newCache(),
61+
bgcache: newBrushCache(),
6062
}
6163

6264
widget.ConnectMousePressEvent(screen.mousePressEvent)
@@ -354,6 +356,13 @@ func (s *Screen) gridFontAutomaticHeight(update interface{}) {
354356
grid = s.ws.cursor.bufferGridid
355357
}
356358

359+
// Workaround for autocmds triggered with BufEnter/BufWinEnter/...
360+
// When a file is opened directly e.g. with `goneovim plainfile.txt`
361+
// would end with applying the new font to the status line.
362+
if grid == 1 {
363+
grid = 2
364+
}
365+
357366
win, ok := s.getWindow(grid)
358367
if !ok {
359368
return
@@ -369,6 +378,7 @@ func (s *Screen) gridFontAutomaticHeight(update interface{}) {
369378
}
370379

371380
font := win.getFont()
381+
oldCellWidth := font.cellwidth
372382

373383
// The font height we'll try to approximate with the new font
374384
oldFontHeight := font.fontMetrics.Height()
@@ -404,12 +414,11 @@ func (s *Screen) gridFontAutomaticHeight(update interface{}) {
404414
for newFontHeight > oldFontHeight {
405415
updateFont(-1)
406416
}
407-
for newFontHeight < oldFontHeight {
408-
updateFont(0.1)
409-
}
410-
for newFontHeight > oldFontHeight {
411-
updateFont(-0.1)
412-
}
417+
418+
// Refresh the screen while the font.cellwidth hasn't change.
419+
// It avoids old text to stay forever, between windows.
420+
// (Especially between window and statusbar.)
421+
s.refresh()
413422

414423
// Build the new font
415424
win.font = initFontNew(fontFamily, newFontSize, font.weight, font.stretch, font.lineSpace, font.letterSpace)
@@ -420,6 +429,13 @@ func (s *Screen) gridFontAutomaticHeight(update interface{}) {
420429
win.fallbackfonts = nil
421430
s.ws.cursor.fallbackfonts = win.fallbackfonts
422431

432+
// Keep the old cellwidth matters. Changing it would impact e.g.
433+
// Window.paint(). Plus, proportional font doesn't have something
434+
// such as a `cellwidth`.
435+
win.font.cellwidth = oldCellWidth
436+
437+
// TODO: Resize Grid if enough space to add a row
438+
423439
// Cache
424440
cache := win.cache
425441
if cache == (Cache{}) {

0 commit comments

Comments
 (0)