@@ -6,7 +6,7 @@ import { type Diagnostic, linter, lintGutter, setDiagnostics } from '@codemirror
66import { EditorState } from '@codemirror/state'
77import { drawSelection , EditorView , highlightActiveLine , highlightActiveLineGutter , keymap , lineNumbers , placeholder } from '@codemirror/view'
88import { tags } from '@lezer/highlight'
9- import { formatSource , jsonProblem , place , type Target } from './json-scan'
9+ import { formatSource , jsonProblem , place , type Target , wholeSource } from './json-scan'
1010
1111/**
1212 * The editor of the build page's source, `/h5p/build/`, in place of its textarea: JSON in colours,
@@ -93,15 +93,16 @@ const typeOverSelection = EditorView.domEventHandlers({
9393 * A source pasted whole, into an empty editor or over all of its text, goes in laid out, and out of
9494 * the code fence a chat put it in, so that the page needs no button for it. A paste into the text,
9595 * or of text that is not JSON, goes in as it is. Where the text is one the page put there to be
96- * pasted over (`over`), a paste anywhere in it replaces all of it, laid out where it is JSON.
96+ * pasted over (`over`), or the paste is a whole source (`wholeSource`), a paste anywhere in it
97+ * replaces all of it, laid out where it is JSON; undo brings the old text back.
9798 */
9899function pasteLaidOut ( over : ( ) => boolean ) {
99100 return EditorView . domEventHandlers ( {
100101 paste ( event , view ) {
101102 const text = event . clipboardData ?. getData ( 'text/plain' )
102103 if ( ! text ) return false
103104 const { from, to } = view . state . selection . main
104- const replaced = over ( )
105+ const replaced = over ( ) || wholeSource ( text )
105106 if ( ! replaced && ( from !== 0 || to !== view . state . doc . length ) ) return false
106107 const insert = formatSource ( text ) ?? ( replaced ? text : null )
107108 if ( insert === null ) return false
0 commit comments