From e5b3921ca45d90a3c92a13b85a2e8af3babad4d5 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 17 Sep 2017 03:35:47 +0000 Subject: [PATCH] Code Editor: Scroll the cursor line into view instead of the entire editor when focused. See #41850. Fixes #41879. Built from https://develop.svn.wordpress.org/trunk@41384 git-svn-id: http://core.svn.wordpress.org/trunk@41217 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/code-editor.js | 6 +++--- wp-admin/js/code-editor.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-admin/js/code-editor.js b/wp-admin/js/code-editor.js index 61891d32bb..e2f187c15f 100644 --- a/wp-admin/js/code-editor.js +++ b/wp-admin/js/code-editor.js @@ -181,10 +181,10 @@ if ( 'undefined' === typeof window.wp.codeEditor ) { $textarea.data( 'next-tab-blurs', false ); }); codemirror.on( 'focus', function() { - if ( codemirror.display.wrapper.scrollIntoViewIfNeeded ) { - codemirror.display.wrapper.scrollIntoViewIfNeeded(); + if ( codemirror.display.cursorDiv.scrollIntoViewIfNeeded ) { + codemirror.display.cursorDiv.scrollIntoViewIfNeeded(); } else { - codemirror.display.wrapper.scrollIntoView(); + codemirror.display.cursorDiv.scrollIntoView(); } }); codemirror.on( 'keydown', function onKeydown( editor, event ) { diff --git a/wp-admin/js/code-editor.min.js b/wp-admin/js/code-editor.min.js index 2b8fbc2b13..da333273fd 100644 --- a/wp-admin/js/code-editor.min.js +++ b/wp-admin/js/code-editor.min.js @@ -1 +1 @@ -"undefined"==typeof window.wp&&(window.wp={}),"undefined"==typeof window.wp.codeEditor&&(window.wp.codeEditor={}),function(a,b){"use strict";function c(b,c){var d,e=b.getOption("lint"),f=[],g=[];e&&(e=!0===e?{}:a.extend({},e),e.options||(e.options={}),"javascript"===c.codemirror.mode&&c.jshint&&a.extend(e.options,c.jshint),"css"===c.codemirror.mode&&c.csslint&&a.extend(e.options,c.csslint),"htmlmixed"===c.codemirror.mode&&c.htmlhint&&(e.options.rules=a.extend({},c.htmlhint),c.jshint&&(e.options.rules.jshint=c.jshint),c.csslint&&(e.options.rules.csslint=c.csslint)),d=function(){c.onUpdateErrorNotice&&!_.isEqual(f,g)&&(c.onUpdateErrorNotice(f,b),g=f)},e.onUpdateLinting=function(a){return function(b,e,h){var i=_.filter(b,function(a){return"error"===a.severity});a&&a.apply(b,e,h),_.isEqual(i,f)||(f=i,c.onChangeLintingErrors&&c.onChangeLintingErrors(i,b,e,h),(!h.state.focused||0===f.length||g.length>0)&&d())}}(e.onUpdateLinting),b.setOption("lint",e),b.on("blur",d),b.on("startCompletion",function(){b.off("blur",d)}),b.on("endCompletion",function(){var a=500;b.on("blur",d),_.delay(function(){b.state.focused||d()},a)}),a(document.body).on("mousedown",function(c){!b.state.focused||a.contains(b.display.wrapper,c.target)||a(c.target).hasClass("CodeMirror-hint")||d()}))}function d(b,c){var d=a(b.getTextArea());b.on("blur",function(){d.data("next-tab-blurs",!1)}),b.on("focus",function(){b.display.wrapper.scrollIntoViewIfNeeded?b.display.wrapper.scrollIntoViewIfNeeded():b.display.wrapper.scrollIntoView()}),b.on("keydown",function(a,e){var f=9,g=27;return g===e.keyCode?void d.data("next-tab-blurs",!0):void(f===e.keyCode&&d.data("next-tab-blurs")&&(e.shiftKey?c.onTabPrevious(b,e):c.onTabNext(b,e),d.data("next-tab-blurs",!1),e.preventDefault()))})}b.codeEditor.defaultSettings={codemirror:{},csslint:{},htmlhint:{},jshint:{},onTabNext:function(){},onTabPrevious:function(){},onChangeLintingErrors:function(){},onUpdateErrorNotice:function(){}},b.codeEditor.instances=[],b.codeEditor.initialize=function(e,f){var g,h,i,j;return g=a("string"==typeof e?"#"+e:e),i=a.extend({},b.codeEditor.defaultSettings,f),i.codemirror=a.extend({},i.codemirror),h=b.CodeMirror.fromTextArea(g[0],i.codemirror),c(h,i),j={settings:i,codemirror:h},b.codeEditor.instances.push(j),h.showHint&&h.on("keyup",function(a,c){var d,e,f,g,i=/^[a-zA-Z]$/.test(c.key);h.state.completionActive&&i||(g=h.getTokenAt(h.getCursor()),"string"!==g.type&&"comment"!==g.type&&(f=b.CodeMirror.innerMode(h.getMode(),g.state).mode.name,e=h.doc.getLine(h.doc.getCursor().line).substr(0,h.doc.getCursor().ch),"html"===f||"xml"===f?d="<"===c.key||"/"===c.key&&"tag"===g.type||i&&"tag"===g.type||i&&"attribute"===g.type||"="===g.string&&g.state.htmlState&&g.state.htmlState.tagName:"css"===f?d=i||":"===c.key||" "===c.key&&/:\s+$/.test(e):"javascript"===f?d=i||"."===c.key:"clike"===f&&"application/x-httpd-php"===h.options.mode&&(d="keyword"===g.type||"variable"===g.type),d&&h.showHint({completeSingle:!1})))}),d(h,f),j}}(window.jQuery,window.wp); \ No newline at end of file +"undefined"==typeof window.wp&&(window.wp={}),"undefined"==typeof window.wp.codeEditor&&(window.wp.codeEditor={}),function(a,b){"use strict";function c(b,c){var d,e=b.getOption("lint"),f=[],g=[];e&&(e=!0===e?{}:a.extend({},e),e.options||(e.options={}),"javascript"===c.codemirror.mode&&c.jshint&&a.extend(e.options,c.jshint),"css"===c.codemirror.mode&&c.csslint&&a.extend(e.options,c.csslint),"htmlmixed"===c.codemirror.mode&&c.htmlhint&&(e.options.rules=a.extend({},c.htmlhint),c.jshint&&(e.options.rules.jshint=c.jshint),c.csslint&&(e.options.rules.csslint=c.csslint)),d=function(){c.onUpdateErrorNotice&&!_.isEqual(f,g)&&(c.onUpdateErrorNotice(f,b),g=f)},e.onUpdateLinting=function(a){return function(b,e,h){var i=_.filter(b,function(a){return"error"===a.severity});a&&a.apply(b,e,h),_.isEqual(i,f)||(f=i,c.onChangeLintingErrors&&c.onChangeLintingErrors(i,b,e,h),(!h.state.focused||0===f.length||g.length>0)&&d())}}(e.onUpdateLinting),b.setOption("lint",e),b.on("blur",d),b.on("startCompletion",function(){b.off("blur",d)}),b.on("endCompletion",function(){var a=500;b.on("blur",d),_.delay(function(){b.state.focused||d()},a)}),a(document.body).on("mousedown",function(c){!b.state.focused||a.contains(b.display.wrapper,c.target)||a(c.target).hasClass("CodeMirror-hint")||d()}))}function d(b,c){var d=a(b.getTextArea());b.on("blur",function(){d.data("next-tab-blurs",!1)}),b.on("focus",function(){b.display.cursorDiv.scrollIntoViewIfNeeded?b.display.cursorDiv.scrollIntoViewIfNeeded():b.display.cursorDiv.scrollIntoView()}),b.on("keydown",function(a,e){var f=9,g=27;return g===e.keyCode?void d.data("next-tab-blurs",!0):void(f===e.keyCode&&d.data("next-tab-blurs")&&(e.shiftKey?c.onTabPrevious(b,e):c.onTabNext(b,e),d.data("next-tab-blurs",!1),e.preventDefault()))})}b.codeEditor.defaultSettings={codemirror:{},csslint:{},htmlhint:{},jshint:{},onTabNext:function(){},onTabPrevious:function(){},onChangeLintingErrors:function(){},onUpdateErrorNotice:function(){}},b.codeEditor.instances=[],b.codeEditor.initialize=function(e,f){var g,h,i,j;return g=a("string"==typeof e?"#"+e:e),i=a.extend({},b.codeEditor.defaultSettings,f),i.codemirror=a.extend({},i.codemirror),h=b.CodeMirror.fromTextArea(g[0],i.codemirror),c(h,i),j={settings:i,codemirror:h},b.codeEditor.instances.push(j),h.showHint&&h.on("keyup",function(a,c){var d,e,f,g,i=/^[a-zA-Z]$/.test(c.key);h.state.completionActive&&i||(g=h.getTokenAt(h.getCursor()),"string"!==g.type&&"comment"!==g.type&&(f=b.CodeMirror.innerMode(h.getMode(),g.state).mode.name,e=h.doc.getLine(h.doc.getCursor().line).substr(0,h.doc.getCursor().ch),"html"===f||"xml"===f?d="<"===c.key||"/"===c.key&&"tag"===g.type||i&&"tag"===g.type||i&&"attribute"===g.type||"="===g.string&&g.state.htmlState&&g.state.htmlState.tagName:"css"===f?d=i||":"===c.key||" "===c.key&&/:\s+$/.test(e):"javascript"===f?d=i||"."===c.key:"clike"===f&&"application/x-httpd-php"===h.options.mode&&(d="keyword"===g.type||"variable"===g.type),d&&h.showHint({completeSingle:!1})))}),d(h,f),j}}(window.jQuery,window.wp); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 4928418909..1c27bdf46d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41383'; +$wp_version = '4.9-alpha-41384'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.