mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fix: Automatically expand code block if find result is within (#12346)
This commit is contained in:
@@ -163,6 +163,7 @@ export default class FindAndReplaceExtension extends Extension<FindAndReplaceOpt
|
||||
|
||||
dispatch?.(state.tr.setMeta(pluginKey, {}));
|
||||
this.expandFoldedTogglesForCurrentMatch();
|
||||
this.expandCollapsedCodeBlockForCurrentMatch();
|
||||
this.scrollToCurrentMatch();
|
||||
|
||||
return true;
|
||||
@@ -213,6 +214,7 @@ export default class FindAndReplaceExtension extends Extension<FindAndReplaceOpt
|
||||
|
||||
dispatch?.(state.tr.setMeta(pluginKey, {}));
|
||||
this.expandFoldedTogglesForCurrentMatch();
|
||||
this.expandCollapsedCodeBlockForCurrentMatch();
|
||||
this.scrollToCurrentMatch();
|
||||
return true;
|
||||
};
|
||||
@@ -298,6 +300,18 @@ export default class FindAndReplaceExtension extends Extension<FindAndReplaceOpt
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a collapsed code block if it contains the current match.
|
||||
*/
|
||||
private expandCollapsedCodeBlockForCurrentMatch() {
|
||||
const result = this.results[this.currentResultIndex];
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.editor.commands.expandCodeBlockAt(result.from);
|
||||
}
|
||||
|
||||
private rebaseNextResult(replace: string, index: number, lastOffset = 0) {
|
||||
const nextIndex = index + 1;
|
||||
|
||||
|
||||
@@ -244,6 +244,29 @@ export default class CodeFence extends Node<CodeFenceOptions> {
|
||||
...attrs,
|
||||
});
|
||||
},
|
||||
expandCodeBlockAt:
|
||||
(pos: number): Command =>
|
||||
(state, dispatch) => {
|
||||
const $pos = state.doc.resolve(pos);
|
||||
const codeBlock = findParentNodeClosestToPos($pos, isCode);
|
||||
if (!codeBlock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const collapseState = CodeFence.collapseKey.getState(state);
|
||||
if (!collapseState?.collapsedBlocks.has(codeBlock.pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
dispatch(
|
||||
state.tr
|
||||
.setMeta(CodeFence.collapseKey, { expand: codeBlock.pos })
|
||||
.setMeta("addToHistory", false)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
toggleCodeBlockCollapse: (): Command => (state, dispatch) => {
|
||||
const codeBlock = findParentNode(isCode)(state.selection);
|
||||
if (!codeBlock) {
|
||||
|
||||
Reference in New Issue
Block a user