Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/components/InputJson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import {createEditor} from "../libs/codemirror-editor-factory";
import type { StylePropertySpecification } from "maplibre-gl";
import { TransactionSpec } from "@codemirror/state";

Check failure on line 10 in src/components/InputJson.tsx

View workflow job for this annotation

GitHub Actions / build on macos-latest

All imports in the declaration are only used as types. Use `import type`

Check failure on line 10 in src/components/InputJson.tsx

View workflow job for this annotation

GitHub Actions / build on windows-latest

All imports in the declaration are only used as types. Use `import type`

Check failure on line 10 in src/components/InputJson.tsx

View workflow job for this annotation

GitHub Actions / build on ubuntu-latest

All imports in the declaration are only used as types. Use `import type`

export type InputJsonProps = {
value: object
Expand Down Expand Up @@ -59,6 +60,7 @@

onFocus = () => {
if (this.props.onFocus) this.props.onFocus();
console.log("focusing");
this.setState({
isEditing: true,
});
Expand All @@ -69,21 +71,24 @@
this.setState({
isEditing: false,
});
console.log("bluring");
};

componentDidUpdate(prevProps: InputJsonProps) {
if (!this.state.isEditing && prevProps.value !== this.props.value) {
this._cancelNextChange = true;
const currentSelection = this._view!.state.selection;
this._view!.dispatch({
const transactionSpec: TransactionSpec = {
changes: {
from: 0,
to: this._view!.state.doc.length,
insert: this.getPrettyJson(this.props.value)
},
selection: currentSelection,
scrollIntoView: true
});
}
};
if ((document.activeElement?.parentNode as HTMLDivElement)?.classList.contains("cm-search")) {
transactionSpec.selection = this._view!.state.selection;
transactionSpec.scrollIntoView = true;
}
this._view!.dispatch(transactionSpec);
}
}

Expand Down
Loading