Skip to content
Merged
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
16 changes: 15 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,22 @@ vim.keymap.set("n", "<leader>md", "<Plug>(md-render-demo)", { desc = "Mar
| `:MdRender pager` | ページャーモード — フルスクリーン、装飾なし、`q` で Neovim 終了 |
| `:MdRender demo` | 対応する全 Markdown 記法のデモウィンドウを表示 |

タブ補完では第1引数としてサブコマンド一覧、`auto` と `textsize` の後では `on` / `off` / `toggle` が候補になります。
`float` / `tab` / `pager` / `toggle` / `split` は `width=N` を取り、そのプレビューを `N` 桁の固定幅で描画します (例: `:MdRender float width=120`)。[描画幅](#描画幅) を参照してください。

タブ補完では、第1引数ではサブコマンド一覧が、`auto` と `textsize` の後では `on` / `off` / `toggle` が、幅を取るサブコマンドの後では `width=` が候補になります。

> **後方互換について。** 従来のトップレベルコマンド (`:MdRenderTab`、`:MdRenderToggle`、`:MdRenderSplit`、`:MdRenderAuto`、`:MdRenderPager`、`:MdRenderDemo`) は新しいディスパッチャへ転送されるエイリアスとして残しています。Neovim セッションごとに最初の呼び出しで非推奨警告を1度だけ表示します。将来のメジャーバージョンで削除されます。

### 描画幅

プレビューはウィンドウの幅で描画し、上限は 80 桁です。ウィンドウの大きさが変わると追従します。上限があるのは、広いウィンドウでも長い行は読みにくいためです。幅の広い表や長い行に広いウィンドウを使わせたいときは上限を上げ、より狭い幅にしたいときは下げます:

```lua
vim.g.md_render_max_width = 120
```

この幅はインデントを含む描画した行全体の幅です。`:MdRender` の `width=N`、または Lua API の `max_width` (`preview.show({ max_width = 120 })`) を使うと、1 つのプレビューだけ幅を固定できます。固定した幅は、ウィンドウの大きさが変わってもそのままです。

### その場トグル

`:MdRender toggle` は、現在のウィンドウをソース Markdown バッファとそのレンダリング表示の間で**その場で**切り替えます。新しいタブやフローティングウィンドウは開きません。スプリットレイアウトでコードと README のレンダリングを並べたい、といった用途を想定しています。
Expand Down Expand Up @@ -243,6 +255,8 @@ require("md-render.text_size").setup { enabled = false }
- どのレベルも 2 行ぶんのブロックを確保しますが、それを埋めるのは `#` だけなので、残りはブロックの中央に配置しています (`v=2`)。プロトコルの既定は上辺揃えで、特に `######` (2 倍の高さのブロックに 1.17 倍) では見出しの下にほぼ 1 行ぶんの空白が残ってしまいます。
- レベルアイコンは等倍のままですが、下地の素のテキストではなく独立した run として描画します。こうすることで同じブロックの中央に揃い、見出しと同じ高さに並びます (`s=2` に対する `n=1:d=2` がセルの拡大をちょうど打ち消します)。独立した run にすることは可読性の面でも必要です。Kitty は拡大されたテキストに元の 1 セルあたり `s` セルだけを割り当てますが、これらの Nerd Font グリフは幅 1 セルと報告されながら実際にはより広く描画されるため、見出しの run に混ぜると切り取られてしまいます(`󰉬` が「H」だけになる)。単独なら `w=1` でアイコンが元々占めている 2 セルぶんのブロックが与えられ、収まります。
- 2 行目がウィンドウの外にはみ出す見出しは、スクロールして見えるようになるまで等倍のままです。
- フローティングウィンドウに一部でも隠れた見出しは、フロートを描きつぶさないよう、フロートが閉じるまで等倍のままです。
- 小数倍で拡大する見出し (`##` 〜 `######`) は、フォントがセルの格子に合っていることを前提にしています。各 run の幅は文字のセル幅から数えた整数セルで指定しますが、Kitty は実際のフォントの送り幅で文字を並べます。両者が食い違うと、和字では run の切れ目に隙間が空き、欧文では run の末尾の文字が欠けることがあります。グリフが 2 セルより狭いフォールバックの CJK フォントで特に目立ちます ([#65](https://github.com/delphinus/md-render.nvim/issues/65))。CJK のグリフがちょうど 2 セル幅の SF Mono Square では、同じ見出しでもどちらも起きません。お使いのフォントで起きる場合は `:MdRender textsize off` で拡大を止められます。
- 他の何かによる再描画(他のプラグインによる強制再描画、メッセージやポップアップの重なり、マウススクロール時に端末がセルをずらす動作)が起きると、見出しは一旦等倍に戻ります。これを防ぐ手段はありません。復帰は 3 つの信号で行っており、届くのが速い順に、スクロール・リサイズ・ウィンドウの開閉は即座に描き直し、それ以外のあらゆる再描画はデコレーションプロバイダで次の tick に拾い、残りを `SafeState` (レート制限あり) と、入力待ちに戻らない再描画のための 500 ms のタイマーが受け持ちます。md-render 自身の再描画はこの経路ではなく正しく処理されます。インライン画像と拡大見出しはどちらも Neovim のグリッドの外に描かれ、どちらも全画面の再描画で消えるため、再描画した側がそれを通知し、もう一方が即座に描き直します。
- **`eventignore = "all"` で囲んで再描画するプラグインがいると、1 フレームだけ取りこぼしが残ります。** これは短縮できません。上に挙げた仕組みはどれも autocmd で「何かが起きた」ことを知りますが、この設定はその autocmd を全部黙らせます。デコレーションプロバイダは autocmd ではないので発火し続け、次の tick で見出しは戻りますが、その 1 フレームだけは消えます。既知の該当例は [nvim-scrollview](https://github.com/dstein64/nvim-scrollview) です。マウスを動かしている間、毎秒約 20 回、エディタ全面のフロートを開き、小さなフロートを十数個動かし、また閉じる、という処理を `eventignore = "all"` で囲んで実行します。15 秒間の実測では `nvim_open_win` の呼び出し 308 回に対して `WinNew` の発火は 1 回でした。プレビューが画面にある間だけ止めたい場合は、開閉イベントを対にするのではなく `b:md_render` (md-render が描画するすべてのバッファで `true`) で判定してください。プレビューは複数開けますし手で分割もできるため、「今開いているか」を問うほうが数える必要が無く確実です:

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ Known limitations:
- Every level reserves a two-row block while only `#` fills it, so the rest are centered in theirs (`v=2`) instead of sitting against the top edge, which is the protocol's default. At `######` — 1.17x in a block twice as tall — the top edge left almost a whole row empty under the heading.
- The level icon stays at normal size, but goes out as a run of its own rather than as the plain text underneath, so it is centered in the same block and stays level with the heading it labels (`n=1:d=2` against `s=2` cancels the cell scale exactly). Its own run is also what keeps it legible: Kitty gives a scaled run exactly `s` cells per source cell, and these Nerd Font glyphs report as one cell wide while being drawn wider, so sharing the heading's run would clip the icon — `󰉬` would render as a bare "H". Alone, `w=1` gives it the two-cell block the icon already occupies, and it fits.
- A heading whose second row would fall outside the window stays plain until scrolled into view.
- A heading that a floating window covers, even in part, stays plain until the float closes, so that it does not paint over the float.
- Fractionally scaled headings (`##` to `######`) rely on the font fitting the cell grid. Each run declares its width in whole cells, counted from the characters' cell widths, while Kitty lays the text out with the font's own glyph advances. Where the two disagree, CJK text gets gaps where one run ends and the next begins, and Latin glyphs can be clipped at the end of a run, most visibly with a fallback CJK font whose glyphs are narrower than two cells ([#65](https://github.com/delphinus/md-render.nvim/issues/65)). With SF Mono Square, whose CJK glyphs are exactly two cells wide, the same headings show neither. If your font shows it, `:MdRender textsize off` turns scaling off.
- A repaint by anything else (another plugin forcing a redraw, a message or popup overlapping the window, the terminal shifting cells for a mouse scroll) drops the heading back to plain size, and there is no way to stop that happening. Recovery is on three signals, in order of how quickly they arrive: a scroll, resize, or window opening or closing repaints at once; any redraw at all is picked up from a decoration provider on the tick after it; and `SafeState` covers the rest, rate-limited, with a 500 ms timer behind it for a repaint that never settles. md-render's own repaints are handled properly rather than waited out — inline images and scaled headings both draw outside Neovim's grid and are both destroyed by a full repaint, so whichever of the two repaints announces it and the other puts itself back at once.
- **A plugin that repaints inside `eventignore = "all"` costs a frame that cannot be recovered any sooner.** Autocmds are how everything above learns that anything happened, and that setting silences all of them. The decoration provider still fires — it is not an autocmd — so the heading comes back on the next tick, but it does go for that one frame. [nvim-scrollview](https://github.com/dstein64/nvim-scrollview) is the known case: it opens a float the size of the whole editor, moves a dozen small ones and closes them again, about twenty times a second while the mouse moves, all of it inside `eventignore = "all"`. Measured over fifteen seconds, 308 calls to `nvim_open_win` produced one `WinNew`. To turn it off while a preview is on screen, match on `b:md_render` (set on every buffer md-render renders into) rather than pairing open and close events — a preview can be opened more than once and split by hand, and asking "is one open" needs no bookkeeping:

Expand Down
10 changes: 10 additions & 0 deletions doc/md-render.jax
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,16 @@ Kitty 0.40 で追加された text sizing protocol (OSC 66) は、テキスト
は拡大中は色が失われ、見出し全体が同じハイライトで描かれます。
- 2 行目がウィンドウの外にはみ出す見出しは、スクロールして見えるようになる
まで等倍のままです。
- フローティングウィンドウに一部でも隠れた見出しは、フロートを描きつぶさないよ
う、フロートが閉じるまで等倍のままです。
- 小数倍で拡大する見出し (`##` 〜 `######`) は、フォントがセルの格子に合っているこ
とを前提にしています。各 run の幅は文字のセル幅から数えた整数セルで指定しま
すが、Kitty は実際のフォントの送り幅で文字を並べます。両者が食い違うと、和字
では run の切れ目に隙間が空き、欧文では run の末尾の文字が欠けることがありま
す。グリフが 2 セルより狭いフォールバックの CJK フォントで特に目立ちます
(#65)。CJK のグリフがちょうど 2 セル幅の SF Mono Square では、同じ見出しでも
どちらも起きません。お使いのフォントで起きる場合は `:MdRender textsize off` で
拡大を止められます。
- 他の何かによる再描画(他のプラグインによる強制再描画、メッセージやポップ
アップの重なり、マウススクロール時に端末がセルをずらす動作)が起きると、
見出しは一旦等倍に戻ります。これを防ぐ手段はありません。復帰は 3 つの信号で
Expand Down
11 changes: 11 additions & 0 deletions doc/md-render.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ Limitations: ~
highlight.
- A heading whose second row would fall outside the window stays plain until
it is scrolled into view.
- A heading that a floating window covers, even in part, stays plain until the
float closes, so that it does not paint over the float.
- Fractionally scaled headings (`##` to `######`) rely on the font fitting the
cell grid. Each run declares its width in whole cells, counted from the
characters' cell widths, while Kitty lays the text out with the font's own
glyph advances. Where the two disagree, CJK text gets gaps where one run
ends and the next begins, and Latin glyphs can be clipped at the end of a
run, most visibly with a fallback CJK font whose glyphs are narrower than
two cells (#65). With SF Mono Square, whose CJK glyphs are exactly two
cells wide, the same headings show neither. If your font shows it,
`:MdRender textsize off` turns scaling off.
- A repaint by anything else (another plugin forcing a redraw, a message or
popup overlapping the window, the terminal shifting cells for a mouse
scroll) drops the heading back to plain size, and there is no way to stop
Expand Down
Loading