@14ch/svelte-md-outliner 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,40 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.10] - 2026-09-15
9
+
10
+ ### Changed
11
+
12
+ - Moving a block up or down now crosses section boundaries. A paragraph, table,
13
+ quote or code block at the edge of a section used to stop there, while a list
14
+ item in the same place moved on into the neighbouring section. Every block now
15
+ takes the same path — down into the section that comes next in the document, up
16
+ into the end of the one before — and the same key in the opposite direction
17
+ brings it back. Blocks nested inside a list item stay where they are.
18
+
19
+ ### Fixed
20
+
21
+ - Selecting several sections and moving them up or down moves all of them. Only
22
+ the first section moved and the rest stayed behind. The headings the selection
23
+ covers now move as one block, keeping their order and their levels relative to
24
+ each other. When those headings sit at different depths, the range widens to
25
+ the depth that holds them all, the way it already does for list items.
26
+
27
+ ## [0.0.9] - 2026-09-12
28
+
29
+ ### Changed
30
+
31
+ - The text cursor and the built-in context menu are limited to the content. The
32
+ editor fills the box you give it, so the empty space below the document, the
33
+ leftover width beside a narrowed column, and the gaps between blocks all used
34
+ to show an I-beam and open the built-in menu. They now show the ordinary
35
+ pointer and leave right-click to the environment's own menu. Clicking there
36
+ still puts the caret at the nearest position, as before. Quotes, tables and
37
+ code blocks count as content in full — their bars, rules and fills read as part
38
+ of the block, not as a gap.
39
+ - Headings now leave 0.75em below them, the same gap paragraphs leave (was
40
+ 0.5em).
41
+
8
42
  ## [0.0.8] - 2026-09-10
9
43
 
10
44
  ### Fixed
@@ -276,17 +276,58 @@
276
276
  background: var(--markdown-editor-background);
277
277
  outline: none;
278
278
  /**
279
- * 編集エリアの上では I ビームにする。
279
+ * 面そのものは**矢印**にする(合図は中身が出す → 次の規則)。
280
280
  *
281
- * 既定(`auto`)だと、文字の上では I ビームでも、内側の余白やブロックの間の空きでは
282
- * 矢印に戻る。そこも押せば文字を打ち始められる場所なので、サーフェス全体で一貫させる。
283
- * 押して別のことが起きるターゲット(折りたたみの記号・表の印・チェック)は、各所で上書きする。
281
+ * **`auto` では矢印にならない。** 編集できる要素の上では、実行環境が中身の有無に関わらず
282
+ * I ビームを出す(Chromium は `contenteditable` の箱なら内側の余白でも I ビームにする)。
283
+ * 指定を消すだけでは面の全体が I ビームのままなので、矢印は明示する。
284
284
  */
285
- cursor: text;
285
+ cursor: default;
286
286
  white-space: pre-wrap;
287
287
  word-wrap: break-word;
288
288
  }
289
289
 
290
+ /**
291
+ * 文字を打つ合図(I ビーム)は、**書かれているものの上だけに出す**。
292
+ *
293
+ * 面は置いた先が与えた箱いっぱいに広がる(→ `.markdown-editor`)。面の全体を I ビームに
294
+ * すると、文書の下に残った空きや、版面を狭めたときの左右の余りまで「ここは文字の場所だ」と
295
+ * 言うことになる。**置いた先の余白と見分けが付かない場所で、編集エリアだけが自己主張する。**
296
+ * 独自のコンテキストメニューも同じ範囲に揃える(→ `contextMenu.ts`)。
297
+ *
298
+ * **押せることは変わらない。** 余りを押せばいちばん近い位置へカーソルが入る
299
+ * (→ `.markdown-editor`)。変えたのは合図を出す範囲だけである。
300
+ *
301
+ * 押して別のことが起きるターゲット(折りたたみの記号・表の印・チェック・帯)は、各所で
302
+ * 上書きする。どれも `.markdown-editor__surface` から始まる規則なので、この規則より強い。
303
+ */
304
+ .markdown-editor__surface * {
305
+ cursor: text;
306
+ }
307
+
308
+ /**
309
+ * **構造の箱は、自分の隙間に合図を出さない。**
310
+ *
311
+ * セクションと箇条書きの項目は、ブロックを並べるだけで自分の見た目を持たない。並んだ
312
+ * ブロックのあいだ(マージン)は、その箱に当たる。そこは面の余りと同じく何も書かれていない
313
+ * 場所なので、中身と同じ合図を出さない(利用者の指摘、2026-09-12)。
314
+ *
315
+ * **見た目を持つ箱(引用・表・コードブロック)は、箱ごと中身として扱う。** 自分の余白に線や
316
+ * 地を持ち(縦棒・罫線・背景)、そこは隙間ではなく中身の一部として見える。並べてしまうと、
317
+ * 引用の縦棒や表の罫線の上で合図が切れる。
318
+ *
319
+ * **この並びは `contextMenu.ts` の `CONTAINERS` と対になる。** 構造の箱を足したら両方へ足す。
320
+ */
321
+ .markdown-editor__surface
322
+ :is(
323
+ .markdown-editor__section,
324
+ .markdown-editor__intro-section,
325
+ .prosemirror-flat-list,
326
+ .list-content
327
+ ) {
328
+ cursor: default;
329
+ }
330
+
290
331
  /**
291
332
  * 最大幅(→ `--markdown-editor-max-width`)。**面ではなく中身に掛ける。**
292
333
  *
@@ -371,7 +412,7 @@
371
412
  content: '';
372
413
  position: absolute;
373
414
  /**
374
- * 帯の上では**押せる合図**を出す。編集エリアはサーフェス全体が I ビームなので、そのままだと
415
+ * 帯の上では**押せる合図**を出す。中身の上は I ビームなので、そのままだと
375
416
  * 押して別のことが起きる場所だと分からない。指定は擬似要素だけに置く(ブロックへ
376
417
  * 置くと `cursor` は継承されるので、中身まで合図が変わる)。
377
418
  */
@@ -715,7 +756,7 @@
715
756
  /* 折りたたみの記号を 1 行目の中央へ合わせるため、行の高さを控えておく */
716
757
  --markdown-editor-heading-line-height: 1.3;
717
758
 
718
- margin: 2em 0 0.5em;
759
+ margin: 2em 0 0.75em;
719
760
  font-size: calc(1em * var(--markdown-editor-heading-scale));
720
761
  line-height: var(--markdown-editor-heading-line-height);
721
762
  font-weight: 600;
@@ -7,7 +7,7 @@ import { isTabEscaped } from '../plugins/tabEscape';
7
7
  import { setBlockKind, toggleHeading } from './block';
8
8
  import { indentInCodeBlock, outdentInCodeBlock } from './codeBlock';
9
9
  import { listCommands, moveItemAcrossSection, paragraphToListItem } from './list';
10
- import { liftSection, moveSection, sinkSection, targetSection, topLevelBlock } from './section';
10
+ import { liftSection, moveBlockAcrossSection, moveSection, sinkSection, targetSection, topLevelBlock } from './section';
11
11
  import { liftSelectedBlock, requiredSelectionBlock, sinkSelectedBlock } from './selectedBlock';
12
12
  import { tableCommands } from './table';
13
13
  const n = outlineSchema.nodes;
@@ -191,20 +191,26 @@ function moveElement(direction) {
191
191
  *
192
192
  * **相手になれるのはブロックだけである。** 見出しはセクションの先頭にしか置けず、
193
193
  * 子のセクションはブロックより後ろにしか置けない。どちらかに行き当たったら、
194
- * そこがブロックの並びの端であり、文書もカーソルも動かさない(要件 5.2)。
194
+ * そこがブロックの並びの端である。
195
+ *
196
+ * 端まで来たら、**隣のセクションの中へ入る**(→ `moveBlockAcrossSection`)。項目だけが
197
+ * 境を越えられて段落・表・引用が止まるのは、書き手から見て同じ 1 つのアウトラインの
198
+ * 中で種別によって進み方が変わることであり、規則として説明できない。
195
199
  */
196
200
  function moveBlock(direction, target, state, dispatch) {
197
201
  const $target = state.doc.resolve(target.pos);
198
202
  const index = $target.index();
199
203
  const neighborIndex = direction === 'up' ? index - 1 : index + 1;
200
- if (neighborIndex < 0 || neighborIndex >= $target.parent.childCount)
201
- return false;
202
- const neighbor = $target.parent.child(neighborIndex);
203
- if (neighbor.type === n.section || neighbor.type === n.heading)
204
- return false;
204
+ const neighbor = neighborIndex >= 0 && neighborIndex < $target.parent.childCount
205
+ ? $target.parent.child(neighborIndex)
206
+ : null;
205
207
  // 項目の先頭は、その項目の本文である。見出しと同じく、その前へは出られない
206
- if ($target.parent.type === n.list && neighborIndex === 0)
207
- return false;
208
+ const atRunEdge = !neighbor ||
209
+ neighbor.type === n.section ||
210
+ neighbor.type === n.heading ||
211
+ ($target.parent.type === n.list && neighborIndex === 0);
212
+ if (atRunEdge)
213
+ return moveBlockAcrossSection(direction, target, state, dispatch);
208
214
  if (!dispatch)
209
215
  return true;
210
216
  const insertAt = direction === 'up' ? target.pos - neighbor.nodeSize : target.pos + neighbor.nodeSize;
@@ -105,15 +105,9 @@ export declare function correctItemDepth(state: EditorState): Transaction | null
105
105
  /**
106
106
  * セクションの端にある項目を、隣のセクションへ送り出す。
107
107
  *
108
- * 同じセクションの中でもう動けなくなったときだけ働く。項目のまま移るので、
109
- * 箇条書きの階層は変わらない。
110
- *
111
- * 「セクションの中で止まる」を選ばないのは、書き手から見て見出しと項目が
112
- * ひと続きのアウトラインだからである。下へ押し続けたら下へ進んでほしい。
113
- *
114
- * 行き先は**文書順で隣にあるセクション**であり、同じ階層とは限らない。子セクションが
115
- * あればそこへ入り、自分のセクションの先頭からはその親へ出る。上下は互いに逆をたどる
116
- * ので、行った先から同じキーで必ず戻れる。
108
+ * 越え方そのものはブロックと同じ(→ `moveBlockAcrossSection`)。ここが持つのは
109
+ * **対象が項目であることの確かめ**だけである。入れ子の項目は `topLevelBlock` が弾く。
110
+ * 境を越えた先で階層をたどり直せないため、越えるのはセクション直下の項目に限る。
117
111
  */
118
112
  export declare function moveItemAcrossSection(direction: MoveDirection): EditorCommand;
119
113
  /**
@@ -3,7 +3,7 @@ import { backspaceCommand, createIndentListCommand, createMoveListCommand, creat
3
3
  import { TextSelection } from 'prosemirror-state';
4
4
  import { outlineSchema } from '../../models/document/schema';
5
5
  import { moveContent, setCursor } from '../transaction';
6
- import { blockContentEnd, blockRunEnd, blockRunStart, coveredEnd, nextSection, previousContainer, topLevelBlock } from './section';
6
+ import { coveredEnd, moveBlockAcrossSection, topLevelBlock } from './section';
7
7
  export const listCommands = {
8
8
  indentList,
9
9
  dedentList,
@@ -340,15 +340,9 @@ function contentlessItem(doc) {
340
340
  /**
341
341
  * セクションの端にある項目を、隣のセクションへ送り出す。
342
342
  *
343
- * 同じセクションの中でもう動けなくなったときだけ働く。項目のまま移るので、
344
- * 箇条書きの階層は変わらない。
345
- *
346
- * 「セクションの中で止まる」を選ばないのは、書き手から見て見出しと項目が
347
- * ひと続きのアウトラインだからである。下へ押し続けたら下へ進んでほしい。
348
- *
349
- * 行き先は**文書順で隣にあるセクション**であり、同じ階層とは限らない。子セクションが
350
- * あればそこへ入り、自分のセクションの先頭からはその親へ出る。上下は互いに逆をたどる
351
- * ので、行った先から同じキーで必ず戻れる。
343
+ * 越え方そのものはブロックと同じ(→ `moveBlockAcrossSection`)。ここが持つのは
344
+ * **対象が項目であることの確かめ**だけである。入れ子の項目は `topLevelBlock` が弾く。
345
+ * 境を越えた先で階層をたどり直せないため、越えるのはセクション直下の項目に限る。
352
346
  */
353
347
  export function moveItemAcrossSection(direction) {
354
348
  const n = outlineSchema.nodes;
@@ -356,35 +350,7 @@ export function moveItemAcrossSection(direction) {
356
350
  const origin = topLevelBlock(state);
357
351
  if (!origin || origin.node.type !== n.list)
358
352
  return false;
359
- // まだ同じセクションの中で動けるなら、ここの出番ではない
360
- const edge = direction === 'down' ? blockRunEnd(origin.container) - 1 : blockRunStart(origin.container);
361
- if (origin.index !== edge)
362
- return false;
363
- const target = direction === 'down'
364
- ? nextSection(state.doc, origin.container, origin.containerPos)
365
- : previousContainer(state.doc, origin.containerPos);
366
- if (!target)
367
- return false;
368
- if (!dispatch)
369
- return true;
370
- // 下へ送るときは見出しの直後、上へ送るときは中身の末尾(子セクションの前)
371
- const insertAt = direction === 'down'
372
- ? target.pos + 1 + target.node.child(0).nodeSize
373
- : blockContentEnd(target.node, target.pos);
374
- const tr = state.tr;
375
- const offsetInItem = state.selection.from - origin.pos;
376
- // 見出しを持たないセクションは中身が空だと成立しない。最後の 1 つならまるごと消す
377
- if (origin.container.type === n.intro_section && origin.container.childCount === 1) {
378
- tr.delete(origin.containerPos, origin.containerPos + origin.container.nodeSize);
379
- }
380
- else {
381
- tr.delete(origin.pos, origin.pos + origin.node.nodeSize);
382
- }
383
- const at = tr.mapping.map(insertAt);
384
- tr.insert(at, origin.node);
385
- setCursor(tr, at + offsetInItem);
386
- dispatch(tr.scrollIntoView());
387
- return true;
353
+ return moveBlockAcrossSection(direction, { kind: 'listItem', node: origin.node, pos: origin.pos }, state, dispatch);
388
354
  };
389
355
  }
390
356
  /**
@@ -1,7 +1,7 @@
1
1
  import type { Node } from 'prosemirror-model';
2
2
  import { type EditorState, type Transaction } from 'prosemirror-state';
3
3
  import { type HeadingLevel, type SectionRef } from '../../models/document/document.types';
4
- import type { EditorCommand, MoveDirection } from '../operations.types';
4
+ import type { EditorCommand, ElementTarget, MoveDirection } from '../operations.types';
5
5
  /**
6
6
  * 見出しを 1 段深くする。直前の兄弟セクションの中身の末尾へ移す。
7
7
  *
@@ -41,8 +41,27 @@ export declare function coveredEnd(state: EditorState): number;
41
41
  * 対象になるのは**カーソルが見出し行にあるとき**だけである。中身のどこにいても
42
42
  * 動かせるようにすると、項目や段落を動かすつもりの操作でセクションごと動いて
43
43
  * しまう。「セクションを動かすには、その見出しにカーソルを置く」を規則にする。
44
+ *
45
+ * 選択が複数の見出しにまたがるときは、**覆った見出しをひとまとまりとして動かす**。
46
+ * 1 つずつ動かすと、隣と入れ替えた先が次の対象になり、対象どうしの並びが崩れる。
44
47
  */
45
48
  export declare function moveSection(direction: MoveDirection): EditorCommand;
49
+ /**
50
+ * セクションの端にあるブロックを、隣のセクションへ送り出す。
51
+ *
52
+ * 同じセクションの中でもう動けなくなったときだけ働く。ブロックはそのまま移るので、
53
+ * 種別も箇条書きの階層も変わらない。
54
+ *
55
+ * 「セクションの中で止まる」を選ばないのは、書き手から見て見出しと中身がひと続きの
56
+ * アウトラインだからである。下へ押し続けたら下へ進んでほしい(Decision 22)。**この理由は
57
+ * 種別を選ばない。** 項目だけが越えられて段落・表・引用が止まるのは、内部の構造が
58
+ * そのまま見えているだけで、書き手の意図には対応していない。
59
+ *
60
+ * 行き先は**文書順で隣にあるセクション**であり、同じ階層とは限らない。子セクションが
61
+ * あればそこへ入り、自分のセクションの先頭からはその親へ出る。上下は互いに逆をたどる
62
+ * ので、行った先から同じキーで必ず戻れる。
63
+ */
64
+ export declare function moveBlockAcrossSection(direction: MoveDirection, target: ElementTarget, state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
46
65
  /**
47
66
  * 同じ階層の見出しをすべてリスト項目へ戻す。
48
67
  *
@@ -4,7 +4,7 @@ import { MAX_HEADING_LEVEL } from '../../models/document/document.types';
4
4
  import { bodyCount, bodyIndex, bodyStart } from '../../models/document/bodySelection';
5
5
  import { outlineSchema } from '../../models/document/schema';
6
6
  import { sectionTree } from '../../models/document/sectionTree';
7
- import { moveContent, setCursor } from '../transaction';
7
+ import { moveContent, selectBlockAt, setCursor } from '../transaction';
8
8
  const n = outlineSchema.nodes;
9
9
  /**
10
10
  * 見出しを 1 段深くする。直前の兄弟セクションの中身の末尾へ移す。
@@ -158,51 +158,100 @@ export function coveredEnd(state) {
158
158
  * 対象になるのは**カーソルが見出し行にあるとき**だけである。中身のどこにいても
159
159
  * 動かせるようにすると、項目や段落を動かすつもりの操作でセクションごと動いて
160
160
  * しまう。「セクションを動かすには、その見出しにカーソルを置く」を規則にする。
161
+ *
162
+ * 選択が複数の見出しにまたがるときは、**覆った見出しをひとまとまりとして動かす**。
163
+ * 1 つずつ動かすと、隣と入れ替えた先が次の対象になり、対象どうしの並びが崩れる。
161
164
  */
162
165
  export function moveSection(direction) {
163
166
  return (state, dispatch) => {
164
- const target = targetSection(state);
165
- if (!target)
167
+ const range = selectedSectionRange(state);
168
+ if (!range)
166
169
  return false;
167
- const $target = state.doc.resolve(target.pos);
168
- const index = $target.index();
169
- const neighborIndex = direction === 'up' ? index - 1 : index + 1;
170
- const neighbor = neighborIndex >= 0 && neighborIndex < $target.parent.childCount
171
- ? $target.parent.child(neighborIndex)
170
+ const neighborIndex = direction === 'up' ? range.startIndex - 1 : range.endIndex;
171
+ const neighbor = neighborIndex >= 0 && neighborIndex < range.parent.childCount
172
+ ? range.parent.child(neighborIndex)
172
173
  : null;
173
174
  // 同じ親の中に兄弟がいなければ、隣のセクションの中へ入る
174
175
  if (!neighbor || neighbor.type !== n.section) {
175
- return moveIntoSiblingSection(direction, state, dispatch);
176
+ return moveIntoSiblingSection(direction, range, state, dispatch);
176
177
  }
177
178
  if (!dispatch)
178
179
  return true;
179
- const size = target.node.nodeSize;
180
- const insertAt = direction === 'up' ? target.pos - neighbor.nodeSize : target.pos + neighbor.nodeSize;
180
+ const insertAt = direction === 'up' ? range.start - neighbor.nodeSize : range.start + neighbor.nodeSize;
181
181
  const tr = state.tr;
182
- const offsetInSection = state.selection.from - target.pos;
183
- tr.delete(target.pos, target.pos + size);
184
- tr.insert(insertAt, target.node);
185
- setCursor(tr, insertAt + offsetInSection);
182
+ tr.delete(range.start, range.end);
183
+ tr.insert(insertAt, range.nodes);
184
+ restoreMovedSelection(tr, state, range, insertAt);
186
185
  dispatch(tr.scrollIntoView());
187
186
  return true;
188
187
  };
189
188
  }
190
189
  /**
191
- * 親の端まで来たセクションを、親の隣のセクションの中へ入れる。
190
+ * 覆った見出しを、**同じ親の下に連続して並ぶ兄弟の列**へ正規化したもの。
191
+ *
192
+ * 覆った見出しの深さが揃わないときは、揃う深さまで浅い側へ広げる。上下移動は深さを
193
+ * 変えない操作なので、深さの違うものを同時に動かす形が無い。箇条書きの上下移動が
194
+ * `findListsRange`(`NodeRange`)で同じ正規化をしているのに合わせる。**階層の違う選択の
195
+ * ための特別な規則は持たない**(`dedent-sibling-preservation` Requirement 4.7 と同じ決め方)。
196
+ */
197
+ function selectedSectionRange(state) {
198
+ const targets = selectedSections(state);
199
+ if (targets.length === 0)
200
+ return null;
201
+ const last = targets[targets.length - 1];
202
+ const $start = state.doc.resolve(targets[0].pos);
203
+ const $end = state.doc.resolve(last.pos + last.node.nodeSize);
204
+ let depth = $start.depth;
205
+ while (depth > 0 && $end.pos > $start.end(depth))
206
+ depth -= 1;
207
+ const parent = $start.node(depth);
208
+ const startIndex = $start.index(depth);
209
+ const endIndex = $end.indexAfter(depth);
210
+ const start = depth === $start.depth ? $start.pos : $start.before(depth + 1);
211
+ const nodes = [];
212
+ let end = start;
213
+ for (let index = startIndex; index < endIndex; index += 1) {
214
+ const child = parent.child(index);
215
+ if (child.type !== n.section)
216
+ return null;
217
+ nodes.push(child);
218
+ end += child.nodeSize;
219
+ }
220
+ return {
221
+ parent,
222
+ parentPos: depth > 0 ? $start.before(depth) : -1,
223
+ startIndex,
224
+ endIndex,
225
+ start,
226
+ end,
227
+ nodes
228
+ };
229
+ }
230
+ /**
231
+ * 動かした先で、もとの選択を張り直す。
232
+ *
233
+ * 取り除いて入れ直すので位置の写し取りでは追えない。中身は変わらないため、範囲の先頭
234
+ * からの隔たりをそのまま移り先へ当てる。
235
+ */
236
+ function restoreMovedSelection(tr, state, range, insertAt) {
237
+ const size = range.end - range.start;
238
+ const moved = (pos) => insertAt + Math.min(Math.max(pos - range.start, 1), size - 1);
239
+ const $from = tr.doc.resolve(moved(state.selection.from));
240
+ const $to = tr.doc.resolve(moved(state.selection.to));
241
+ tr.setSelection(TextSelection.between($from, $to));
242
+ }
243
+ /**
244
+ * 親の端まで来た範囲を、親の隣のセクションの中へ入れる。
192
245
  *
193
246
  * 上下移動は「文書順で次(前)にある、同じ深さの置ける位置」へ進む。同じ親の中に
194
247
  * 兄弟がいなければ、次に置けるのは隣のセクションの中である。下へなら子セクションの
195
248
  * 先頭、上へなら末尾。深さは変わらないため、昇格・降格は起きない。
196
249
  */
197
- function moveIntoSiblingSection(direction, state, dispatch) {
198
- const target = targetSection(state);
199
- if (!target)
200
- return false;
201
- const $target = state.doc.resolve(target.pos);
202
- const parent = $target.parent;
250
+ function moveIntoSiblingSection(direction, range, state, dispatch) {
251
+ const parent = range.parent;
203
252
  if (parent.type !== n.section)
204
253
  return false;
205
- const parentPos = $target.before();
254
+ const parentPos = range.parentPos;
206
255
  const $parent = state.doc.resolve(parentPos);
207
256
  const neighborIndex = direction === 'down' ? $parent.index() + 1 : $parent.index() - 1;
208
257
  if (neighborIndex < 0 || neighborIndex >= $parent.parent.childCount)
@@ -217,11 +266,64 @@ function moveIntoSiblingSection(direction, state, dispatch) {
217
266
  ? blockContentEnd(neighbor, neighborPos)
218
267
  : neighborPos + neighbor.nodeSize - 1;
219
268
  const tr = state.tr;
220
- const offsetInSection = state.selection.from - target.pos;
221
- tr.delete(target.pos, target.pos + target.node.nodeSize);
269
+ tr.delete(range.start, range.end);
270
+ const at = tr.mapping.map(insertAt);
271
+ tr.insert(at, range.nodes);
272
+ restoreMovedSelection(tr, state, range, at);
273
+ dispatch(tr.scrollIntoView());
274
+ return true;
275
+ }
276
+ /**
277
+ * セクションの端にあるブロックを、隣のセクションへ送り出す。
278
+ *
279
+ * 同じセクションの中でもう動けなくなったときだけ働く。ブロックはそのまま移るので、
280
+ * 種別も箇条書きの階層も変わらない。
281
+ *
282
+ * 「セクションの中で止まる」を選ばないのは、書き手から見て見出しと中身がひと続きの
283
+ * アウトラインだからである。下へ押し続けたら下へ進んでほしい(Decision 22)。**この理由は
284
+ * 種別を選ばない。** 項目だけが越えられて段落・表・引用が止まるのは、内部の構造が
285
+ * そのまま見えているだけで、書き手の意図には対応していない。
286
+ *
287
+ * 行き先は**文書順で隣にあるセクション**であり、同じ階層とは限らない。子セクションが
288
+ * あればそこへ入り、自分のセクションの先頭からはその親へ出る。上下は互いに逆をたどる
289
+ * ので、行った先から同じキーで必ず戻れる。
290
+ */
291
+ export function moveBlockAcrossSection(direction, target, state, dispatch) {
292
+ const $block = state.doc.resolve(target.pos);
293
+ const container = $block.parent;
294
+ if (container.type !== n.section && container.type !== n.intro_section)
295
+ return false;
296
+ // まだ同じセクションの中で動けるなら、ここの出番ではない
297
+ const edge = direction === 'down' ? blockRunEnd(container) - 1 : blockRunStart(container);
298
+ if ($block.index() !== edge)
299
+ return false;
300
+ const containerPos = $block.before();
301
+ const destination = direction === 'down'
302
+ ? nextSection(state.doc, container, containerPos)
303
+ : previousContainer(state.doc, containerPos);
304
+ if (!destination)
305
+ return false;
306
+ if (!dispatch)
307
+ return true;
308
+ // 下へ送るときは見出しの直後、上へ送るときは中身の末尾(子セクションの前)
309
+ const insertAt = direction === 'down'
310
+ ? destination.pos + 1 + destination.node.child(0).nodeSize
311
+ : blockContentEnd(destination.node, destination.pos);
312
+ const tr = state.tr;
313
+ const offsetInBlock = state.selection.from - target.pos;
314
+ // 見出しを持たないセクションは中身が空だと成立しない。最後の 1 つならまるごと消す
315
+ if (container.type === n.intro_section && container.childCount === 1) {
316
+ tr.delete(containerPos, containerPos + container.nodeSize);
317
+ }
318
+ else {
319
+ tr.delete(target.pos, target.pos + target.node.nodeSize);
320
+ }
222
321
  const at = tr.mapping.map(insertAt);
223
322
  tr.insert(at, target.node);
224
- setCursor(tr, at + offsetInSection);
323
+ if (target.kind === 'selectedBlock')
324
+ selectBlockAt(tr, at);
325
+ else
326
+ setCursor(tr, at + offsetInBlock);
225
327
  dispatch(tr.scrollIntoView());
226
328
  return true;
227
329
  }
@@ -102,12 +102,14 @@ export function createContextMenuPlugin(options) {
102
102
  * | 順 | 押された場所 | 挙動 |
103
103
  * | -- | -------------------------------------- | ---------------------------------------- |
104
104
  * | 1 | 要選択ブロックの押せる帯の上 | そのブロックを指して開く |
105
- * | 2 | 空でない文字列選択の内側 | 受け止めない(実行環境の既定に委ねる) |
106
- * | 3 | セル選択・ブロックを指す状態の内側 | 選択を保って開く |
107
- * | 4 | それ以外 | その位置へカーソルを置いて開く |
105
+ * | 2 | 書かれているものの外(余り・隙間) | 受け止めない(実行環境の既定に委ねる) |
106
+ * | 3 | 空でない文字列選択の内側 | 受け止めない(実行環境の既定に委ねる) |
107
+ * | 4 | セル選択・ブロックを指す状態の内側 | 選択を保って開く |
108
+ * | 5 | それ以外 | その位置へカーソルを置いて開く |
108
109
  *
109
- * 2 は既定のメニューにしかできないこと(コピー・辞書引き・翻訳)へ譲るためである。
110
- * 3 はカーソルを移すと行・列の削除が消えるためである。
110
+ * 2 は面の余りとブロックどうしの隙間(→ `onContent`)。3 は既定のメニューにしかできない
111
+ * こと(コピー・辞書引き・翻訳)へ譲るためである。4 はカーソルを移すと行・列の削除が
112
+ * 消えるためである。
111
113
  *
112
114
  * **帯を最初に見る。** 帯はブロックの箱の外にあり、そこには文書の位置が無い
113
115
  * (`posAtCoords` が答えない)。選択の内側かどうかは位置が要るため、後段では判定できない。
@@ -119,6 +121,8 @@ function handleContextMenu(view, event, options, pressedSelection) {
119
121
  view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, band.pos)));
120
122
  }
121
123
  else {
124
+ if (!onContent(view, event))
125
+ return false;
122
126
  const pos = posAt(view, event);
123
127
  if (pos === undefined)
124
128
  return false;
@@ -143,6 +147,38 @@ function handleContextMenu(view, event, options, pressedSelection) {
143
147
  event.preventDefault();
144
148
  return true;
145
149
  }
150
+ /**
151
+ * 配下をブロックとして並べるだけの箱。**並びは `editor.css` の合図の規則と対になる。**
152
+ *
153
+ * 自分の見た目を持たないものだけを並べる。見た目を持つ箱(引用・表・コードブロック)は
154
+ * 箱ごと中身として扱う(→ `editor.css`)。構造の箱を足したら両方へ足す。
155
+ */
156
+ const CONTAINERS = [
157
+ '.markdown-editor__section',
158
+ '.markdown-editor__intro-section',
159
+ '.prosemirror-flat-list',
160
+ '.list-content'
161
+ ].join(', ');
162
+ /**
163
+ * 押された場所が**書かれているものの上**か。
164
+ *
165
+ * 何も書かれていない場所が 2 通りある。**面の余り**——面は置いた先が与えた箱いっぱいに
166
+ * 広がる(→ `editor.css` の `.markdown-editor`)ので、内側の余白・版面の左右の余り・文書の
167
+ * 下の空きも面の一部である。そして**ブロックどうしの隙間**——並んだブロックのマージンは、
168
+ * それを並べている箱に当たる。どちらも押しただけでこのモジュールのメニューが出ると、
169
+ * 置いた先の余白や行間まで持ち場のように振る舞うことになる(利用者の指摘、2026-09-12)。
170
+ * **合図(I ビーム)を出す範囲と揃える。**
171
+ *
172
+ * **当たった要素で見る。座標から位置を引かない。** `posAtCoords` は隙間の上でもいちばん近い
173
+ * 位置を答えるため、隙間かどうかを区別できない。当たり判定は寄せずに、その点を占めている
174
+ * 箱をそのまま返す(ブロックの箱の外にある帯も、擬似要素なので当たりはブロックになる)。
175
+ */
176
+ function onContent(view, event) {
177
+ const target = event.target;
178
+ if (!(target instanceof Element) || target === view.dom)
179
+ return false;
180
+ return !target.matches(CONTAINERS);
181
+ }
146
182
  /** 押された座標が指す文書の位置。ブロックの箱の外(帯の上)では答えが無い */
147
183
  function posAt(view, event) {
148
184
  return view.posAtCoords({ left: event.clientX, top: event.clientY })?.pos;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@14ch/svelte-md-outliner",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "An outliner-style Markdown editor for Svelte 5. Headings form a real section tree you can fold, focus, and re-nest from the keyboard.",