@14ch/svelte-md-outliner 0.0.9 → 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 +21 -2
- package/dist/operations/commands/element.js +15 -9
- package/dist/operations/commands/list.d.ts +3 -9
- package/dist/operations/commands/list.js +5 -39
- package/dist/operations/commands/section.d.ts +20 -1
- package/dist/operations/commands/section.js +128 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,25 @@ 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
|
+
|
|
8
27
|
## [0.0.9] - 2026-09-12
|
|
9
28
|
|
|
10
29
|
### Changed
|
|
@@ -15,8 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
15
34
|
to show an I-beam and open the built-in menu. They now show the ordinary
|
|
16
35
|
pointer and leave right-click to the environment's own menu. Clicking there
|
|
17
36
|
still puts the caret at the nearest position, as before. Quotes, tables and
|
|
18
|
-
code blocks count as content in full — their bars, rules and fills read as
|
|
19
|
-
|
|
37
|
+
code blocks count as content in full — their bars, rules and fills read as part
|
|
38
|
+
of the block, not as a gap.
|
|
20
39
|
- Headings now leave 0.75em below them, the same gap paragraphs leave (was
|
|
21
40
|
0.5em).
|
|
22
41
|
|
|
@@ -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
|
-
*
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
207
|
-
|
|
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 {
|
|
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
|
|
165
|
-
if (!
|
|
167
|
+
const range = selectedSectionRange(state);
|
|
168
|
+
if (!range)
|
|
166
169
|
return false;
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
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
|
|
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
|
-
|
|
183
|
-
tr.
|
|
184
|
-
tr
|
|
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
|
|
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 =
|
|
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
|
-
|
|
221
|
-
|
|
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
|
-
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@14ch/svelte-md-outliner",
|
|
3
|
-
"version": "0.0.
|
|
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.",
|