Merge "fix scroll behavior of CodeMirror 6"

This commit is contained in:
jenkins-bot 2024-03-01 19:25:00 +00:00 committed by Gerrit Code Review
commit 21a6adca11
6 changed files with 22 additions and 13 deletions

8
package-lock.json generated
View file

@ -14,7 +14,7 @@
"@codemirror/language": "6.9.3",
"@codemirror/search": "6.5.4",
"@codemirror/state": "6.2.1",
"@codemirror/view": "6.18.1",
"@codemirror/view": "6.22.2",
"@lezer/highlight": "1.2.0",
"@wdio/cli": "7.30.1",
"@wdio/junit-reporter": "7.29.1",
@ -1404,9 +1404,9 @@
"dev": true
},
"node_modules/@codemirror/view": {
"version": "6.18.1",
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.18.1.tgz",
"integrity": "sha512-xcsXcMkIMd7l3WZEWoc4ljteAiqzxb5gVerRxk5132p5cLix6rTydWTQjsj2oxORepfsrwy1fC4r20iMa9plrg==",
"version": "6.22.2",
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.22.2.tgz",
"integrity": "sha512-cJp64cPXm7QfSBWEXK+76+hsZCGHupUgy8JAbSzMG6Lr0rfK73c1CaWITVW6hZVkOnAFxJTxd0PIuynNbzxYPw==",
"dev": true,
"dependencies": {
"@codemirror/state": "^6.1.4",

View file

@ -27,7 +27,7 @@
"@codemirror/language": "6.9.3",
"@codemirror/search": "6.5.4",
"@codemirror/state": "6.2.1",
"@codemirror/view": "6.18.1",
"@codemirror/view": "6.22.2",
"@lezer/highlight": "1.2.0",
"@wdio/cli": "7.30.1",
"@wdio/junit-reporter": "7.29.1",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -192,6 +192,10 @@ export default class CodeMirror {
if ( this.$textarea[ 0 ].form ) {
this.$textarea[ 0 ].form.addEventListener( 'submit', () => {
this.$textarea.val( this.view.state.doc.toString() );
const scrollTop = document.getElementById( 'wpScrolltop' );
if ( scrollTop ) {
scrollTop.value = this.view.scrollDOM.scrollTop;
}
} );
}

View file

@ -82,13 +82,18 @@ export default class CodeMirrorWikiEditor extends CodeMirror {
this.initialize( extensions );
// Sync scroll position, selections, and focus state.
this.view.scrollDOM.scrollTop = scrollTop;
this.view.dispatch( {
selection: EditorSelection.create( [
EditorSelection.range( selectionStart, selectionEnd )
] ),
scrollIntoView: true
requestAnimationFrame( () => {
this.view.scrollDOM.scrollTop = scrollTop;
} );
if ( selectionStart !== 0 || selectionEnd !== 0 ) {
const range = EditorSelection.range( selectionStart, selectionEnd ),
scrollEffect = EditorView.scrollIntoView( range );
scrollEffect.value.isSnapshot = true;
this.view.dispatch( {
selection: EditorSelection.create( [ range ] ),
effects: scrollEffect
} );
}
if ( hasFocus ) {
this.view.focus();
}