@blankdotpage/cake 0.1.51 → 0.1.52
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/heading/heading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/heading/heading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;AAwW5B,eAAO,MAAM,gBAAgB,EAAE,aAwM9B,CAAC"}
|
|
@@ -157,10 +157,10 @@ function handleMultilineInsertInHeading(state, text) {
|
|
|
157
157
|
},
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
function
|
|
161
|
-
const { source, selection, map } = state;
|
|
160
|
+
function handleLineBreakInHeading(state) {
|
|
161
|
+
const { source, selection, map, runtime } = state;
|
|
162
162
|
if (selection.start !== selection.end) {
|
|
163
|
-
return
|
|
163
|
+
return null;
|
|
164
164
|
}
|
|
165
165
|
const cursorPos = selection.start;
|
|
166
166
|
const sourcePos = map.cursorToSource(cursorPos, "forward");
|
|
@@ -172,11 +172,30 @@ function shouldExitHeadingOnLineBreak(state) {
|
|
|
172
172
|
const lineContent = source.slice(lineStart, lineEnd);
|
|
173
173
|
const match = lineContent.match(HEADING_PATTERN);
|
|
174
174
|
if (!match) {
|
|
175
|
-
return
|
|
175
|
+
return null;
|
|
176
176
|
}
|
|
177
177
|
const marker = match[0];
|
|
178
178
|
const contentStart = lineStart + marker.length;
|
|
179
|
-
|
|
179
|
+
if (sourcePos < contentStart || sourcePos > lineEnd) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
// Enter at the visual start of a heading should create a paragraph above
|
|
183
|
+
// the heading, not leave an empty heading wrapper behind.
|
|
184
|
+
const beforeCursor = source.slice(contentStart, sourcePos);
|
|
185
|
+
if (beforeCursor.trim().length === 0) {
|
|
186
|
+
const nextSource = source.slice(0, lineStart) + "\n" + source.slice(lineStart);
|
|
187
|
+
const next = runtime.createState(nextSource);
|
|
188
|
+
const caretCursor = next.map.sourceToCursor(lineStart, "forward");
|
|
189
|
+
return {
|
|
190
|
+
source: nextSource,
|
|
191
|
+
selection: {
|
|
192
|
+
start: caretCursor.cursorOffset,
|
|
193
|
+
end: caretCursor.cursorOffset,
|
|
194
|
+
affinity: caretCursor.affinity,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return { type: "exit-block-wrapper" };
|
|
180
199
|
}
|
|
181
200
|
function handleToggleHeading(state, targetLevel) {
|
|
182
201
|
const { source, selection, map, runtime } = state;
|
|
@@ -272,10 +291,7 @@ export const headingExtension = (editor) => {
|
|
|
272
291
|
return handleDeleteBackward(state);
|
|
273
292
|
}
|
|
274
293
|
if (command.type === "insert-line-break") {
|
|
275
|
-
|
|
276
|
-
return { type: "exit-block-wrapper" };
|
|
277
|
-
}
|
|
278
|
-
return null;
|
|
294
|
+
return handleLineBreakInHeading(state);
|
|
279
295
|
}
|
|
280
296
|
if (command.type === "insert") {
|
|
281
297
|
const multiline = handleMultilineInsertInHeading(state, command.text);
|