mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-25 20:40:36 +03:00
B: Fix boolean envelopement
This commit is contained in:
parent
a99734ac0e
commit
9524727391
|
@ -17,8 +17,6 @@ export function TabBlockChildren() {
|
|||
const children_operations = useWatch({ control, name: 'children_operations' });
|
||||
const exclude = parent ? [-parent, ...manager.oss.hierarchy.expandAllInputs([-parent]).filter(id => id < 0)] : [];
|
||||
|
||||
console.log(exclude);
|
||||
|
||||
const value = [...children_blocks.map(id => -id), ...children_operations];
|
||||
|
||||
function handleChangeSelected(newValue: number[]) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Formatted text editing helpers
|
||||
|
||||
import { type ReactCodeMirrorRef } from '@uiw/react-codemirror';
|
||||
import { type ReactCodeMirrorRef, type SelectionRange } from '@uiw/react-codemirror';
|
||||
|
||||
import { CodeMirrorWrapper } from '@/utils/codemirror';
|
||||
|
||||
|
@ -145,8 +145,7 @@ export class RSTextWrapper extends CodeMirrorWrapper {
|
|||
return true;
|
||||
}
|
||||
case TokenID.BOOLEAN: {
|
||||
const selStart = selection.from;
|
||||
if (hasSelection && this.ref.view.state.sliceDoc(selStart, selStart + 1) === 'ℬ') {
|
||||
if (hasSelection && this.startsWithBoolean(selection)) {
|
||||
this.envelopeWith('ℬ', '');
|
||||
} else {
|
||||
this.envelopeWith('ℬ(', ')');
|
||||
|
@ -285,4 +284,35 @@ export class RSTextWrapper extends CodeMirrorWrapper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private startsWithBoolean(range: SelectionRange): boolean {
|
||||
const text = this.ref.view.state.sliceDoc(range.from, range.to);
|
||||
if (!text.startsWith('ℬ') || !text.endsWith(')')) {
|
||||
return false;
|
||||
}
|
||||
const openParenIndex = text.indexOf('(', 1);
|
||||
if (openParenIndex === -1) {
|
||||
return false;
|
||||
}
|
||||
for (const char of text.slice(0, openParenIndex)) {
|
||||
if (char !== 'ℬ') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const bracketsContent = text.slice(openParenIndex + 1, text.length - 1);
|
||||
return this.isValidBracketSequence(bracketsContent);
|
||||
}
|
||||
|
||||
private isValidBracketSequence(text: string): boolean {
|
||||
let depth = 0;
|
||||
for (const char of text) {
|
||||
if (char === '(') {
|
||||
depth++;
|
||||
} else if (char === ')') {
|
||||
depth--;
|
||||
if (depth < 0) return false;
|
||||
}
|
||||
}
|
||||
return depth === 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user