mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-23 13:56:44 +00:00
Merge "fix scroll behavior of CodeMirror 6"
This commit is contained in:
commit
21a6adca11
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
2
resources/dist/main.js
vendored
2
resources/dist/main.js
vendored
File diff suppressed because one or more lines are too long
2
resources/dist/main.js.map.json
vendored
2
resources/dist/main.js.map.json
vendored
File diff suppressed because one or more lines are too long
|
@ -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;
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue