From ea2c2949c101880eab00c6d679cff6a4a0d2205a Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 8 Dec 2020 15:36:06 +0000 Subject: [PATCH 01/12] working clicking on side div line number to set line number hash and then on visiting scrolling back into view --- src/static/css/iframe_editor.css | 1 + src/static/js/pad_editor.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/static/css/iframe_editor.css b/src/static/css/iframe_editor.css index 7267375a473..42951f486b7 100644 --- a/src/static/css/iframe_editor.css +++ b/src/static/css/iframe_editor.css @@ -101,6 +101,7 @@ body.mozilla, body.safari { font-size: 9px; padding: 0 14px 0 10px; font-family: monospace; + cursor: pointer; } .plugin-ep_author_neat #sidedivinner.authorColors .line-number { padding-right: 10px; diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index e7e72308039..aeff98c9e21 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -1,3 +1,4 @@ +'use strict'; /** * This code is mostly from the old Etherpad. Please help us to comment this code. * This helps other people to understand this code better and helps them to improve it. @@ -29,7 +30,7 @@ const padeditor = (function () { let pad = undefined; let settings = undefined; - var self = { + const self = { ace: null, // this is accessed directly from other files viewZoom: 100, @@ -41,6 +42,33 @@ const padeditor = (function () { function aceReady() { $('#editorloadingbox').hide(); if (readyFunc) { + // If a number is in the URI IE #L124 go to that line number + const lineNumber = window.location.hash.substr(1); + if (lineNumber) { + if (lineNumber[0] === 'L') { + const lineNumberInt = parseInt(lineNumber.replace('L', '')); + const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') + .contents().find('#innerdocbody'); + const line = $inner.find(`div:nth-child(${lineNumberInt})`); + if (line.length !== 0) { + let offsetTop = line.offset().top; + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); + offsetTop += parseInt($outerdoc.css('padding-top').replace('px', '')); + offsetTop += parseInt($inner.css('padding-top').replace('px', '')); + const $outerdocHTML = $('iframe[name="ace_outer"]').contents() + .find('#outerdocbody').parent(); + $outerdoc.css({top: `${offsetTop}px`}); // Chrome + $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + } + } + } + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); + // Listen for clicks on sidediv items + $outerdoc.find('#sidedivinner').on('click', 'div', function() { + const lineNumber = $(this).index() + 1; + window.location.hash = 'L' + lineNumber; + }) + readyFunc(); } } From 46805d80d62a6cbfb5dfdfb4e8238ecd25f1b336 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 8 Dec 2020 15:48:53 +0000 Subject: [PATCH 02/12] smell resolve --- src/static/js/pad_editor.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index aeff98c9e21..1c215b24cff 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -41,28 +41,29 @@ const padeditor = (function () { function aceReady() { $('#editorloadingbox').hide(); + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); if (readyFunc) { // If a number is in the URI IE #L124 go to that line number const lineNumber = window.location.hash.substr(1); if (lineNumber) { if (lineNumber[0] === 'L') { const lineNumberInt = parseInt(lineNumber.replace('L', '')); - const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') - .contents().find('#innerdocbody'); - const line = $inner.find(`div:nth-child(${lineNumberInt})`); - if (line.length !== 0) { - let offsetTop = line.offset().top; - const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); - offsetTop += parseInt($outerdoc.css('padding-top').replace('px', '')); - offsetTop += parseInt($inner.css('padding-top').replace('px', '')); - const $outerdocHTML = $('iframe[name="ace_outer"]').contents() - .find('#outerdocbody').parent(); - $outerdoc.css({top: `${offsetTop}px`}); // Chrome - $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + if (lineNumberInt) { + const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') + .contents().find('#innerdocbody'); + const line = $inner.find(`div:nth-child(${lineNumberInt})`); + if (line.length !== 0) { + let offsetTop = line.offset().top; + offsetTop += parseInt($outerdoc.css('padding-top').replace('px', '')); + offsetTop += parseInt($inner.css('padding-top').replace('px', '')); + const $outerdocHTML = $('iframe[name="ace_outer"]').contents() + .find('#outerdocbody').parent(); + $outerdoc.css({top: `${offsetTop}px`}); // Chrome + $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + } } } } - const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); // Listen for clicks on sidediv items $outerdoc.find('#sidedivinner').on('click', 'div', function() { const lineNumber = $(this).index() + 1; From 1a577d53bd414c963253ac5f2e9176f41fe25d32 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 8 Dec 2020 15:49:41 +0000 Subject: [PATCH 03/12] smell resolve --- src/static/js/pad_editor.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index 1c215b24cff..23ac931e369 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -65,10 +65,10 @@ const padeditor = (function () { } } // Listen for clicks on sidediv items - $outerdoc.find('#sidedivinner').on('click', 'div', function() { - const lineNumber = $(this).index() + 1; - window.location.hash = 'L' + lineNumber; - }) + $outerdoc.find('#sidedivinner').on('click', 'div', function () { + const targetLineNumber = $(this).index() + 1; + window.location.hash = `L${targetLineNumber}`; + }); readyFunc(); } From a2a7322226549668a1a74948342f328b4dfd2be1 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 10 Dec 2020 23:23:28 +0000 Subject: [PATCH 04/12] focus caret at line --- src/static/js/ace2_inner.js | 1 + src/static/js/pad_editor.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 06e8908e344..99fd9795ed5 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -682,6 +682,7 @@ function Ace2Inner() { editorInfo.ace_doReturnKey = doReturnKey; editorInfo.ace_isBlockElement = isBlockElement; editorInfo.ace_getLineListType = getLineListType; + editorInfo.ace_setSelection = setSelection; editorInfo.ace_callWithAce = function (fn, callStack, normalize) { let wrapper = function () { diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index 23ac931e369..e918ded6d39 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -60,6 +60,24 @@ const padeditor = (function () { .find('#outerdocbody').parent(); $outerdoc.css({top: `${offsetTop}px`}); // Chrome $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + const node = line[0]; + self.ace.callWithAce((ace) => { + const selection = { + startPoint: { + index: 0, + focusAtStart: true, + maxIndex: 1, + node, + }, + endPoint: { + index: 0, + focusAtStart: true, + maxIndex: 1, + node, + }, + }; + ace.ace_setSelection(selection); + }); } } } From 1956b29093a0b39d56742daf8121b608c735557e Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 11 Dec 2020 14:17:05 +0000 Subject: [PATCH 05/12] jshint and test --- tests/frontend/helper.js | 28 +++++++++++++++++----------- tests/frontend/specs/scrollTo.js | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100755 tests/frontend/specs/scrollTo.js diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js index b49d32eb8a1..37c5af3b11a 100644 --- a/tests/frontend/helper.js +++ b/tests/frontend/helper.js @@ -1,4 +1,5 @@ -var helper = {}; +'use strict'; +const helper = {}; // eslint-disable-line (function () { let $iframe; const @@ -29,10 +30,9 @@ var helper = {}; const getFrameJQuery = function ($iframe) { /* - I tried over 9000 ways to inject javascript into iframes. + I tried over 9001 ways to inject javascript into iframes. This is the only way I found that worked in IE 7+8+9, FF and Chrome */ - const win = $iframe[0].contentWindow; const doc = win.document; @@ -68,7 +68,8 @@ var helper = {}; // I don't fully understand it, but this function seems to properly simulate // padCookie.setPref in the client code helper.setPadPrefCookie = function (prefs) { - helper.padChrome$.document.cookie = (`prefsHttp=${escape(JSON.stringify(prefs))};expires=Thu, 01 Jan 3000 00:00:00 GMT`); + helper.padChrome$.document.cookie = + (`prefsHttp=${escape(JSON.stringify(prefs))};expires=Thu, 01 Jan 3000 00:00:00 GMT`); }; // Functionality for knowing what key event type is required for tests @@ -102,8 +103,13 @@ var helper = {}; } // if opts.params is set we manipulate the URL to include URL parameters IE ?foo=Bah. + let encodedParams; if (opts.params) { - var encodedParams = `?${$.param(opts.params)}`; + encodedParams = `?${$.param(opts.params)}`; + } + let hash; + if (opts.hash) { + hash = `#${opts.hash}`; } // clear cookies @@ -112,8 +118,7 @@ var helper = {}; } if (!padName) padName = `FRONTEND_TEST_${helper.randomString(20)}`; - $iframe = $(``); - + $iframe = $(``); // needed for retry const origPadName = padName; @@ -132,7 +137,8 @@ var helper = {}; if (opts.padPrefs) { helper.setPadPrefCookie(opts.padPrefs); } - helper.waitFor(() => !$iframe.contents().find('#editorloadingbox').is(':visible'), 10000).done(() => { + helper.waitFor(() => !$iframe.contents().find('#editorloadingbox') + .is(':visible'), 10000).done(() => { helper.padOuter$ = getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]')); helper.padInner$ = getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]')); @@ -175,7 +181,7 @@ var helper = {}; }; helper.waitFor = function (conditionFunc, timeoutTime = 1900, intervalTime = 10) { - const deferred = $.Deferred(); + const deferred = $.Deferred(); // eslint-disable-line const _fail = deferred.fail.bind(deferred); let listenForFail = false; @@ -245,7 +251,7 @@ var helper = {}; selection.addRange(range); }; - var getTextNodeAndOffsetOf = function ($targetLine, targetOffsetAtLine) { + const getTextNodeAndOffsetOf = function ($targetLine, targetOffsetAtLine) { const $textNodes = $targetLine.find('*').contents().filter(function () { return this.nodeType === Node.TEXT_NODE; }); @@ -268,7 +274,7 @@ var helper = {}; }); // edge cases - if (textNodeWhereOffsetIs === null) { + if (textNodeWhereOffsetIs == null) { // there was no text node inside $targetLine, so it is an empty line (
). // Use beginning of line textNodeWhereOffsetIs = $targetLine.get(0); diff --git a/tests/frontend/specs/scrollTo.js b/tests/frontend/specs/scrollTo.js new file mode 100755 index 00000000000..7509cec1bb7 --- /dev/null +++ b/tests/frontend/specs/scrollTo.js @@ -0,0 +1,24 @@ +'use strict'; + +describe('scrolls to line', function () { + // create a new pad with URL hash set before each test run + beforeEach(function (cb) { + helper.newPad({ + hash: 'L4', + cb, + }); + this.timeout(10000); + }); + + + it('Scrolls down to Line 4', function (done) { + this.timeout(10000); + const chrome$ = helper.padChrome$; + helper.waitFor(() => { + const topOffset = parseInt(chrome$('iframe').first('iframe') + .contents().find('#outerdocbody').css('top')); + return (topOffset >= 100); + }); + done(); + }); +}); From 78fe277ac6aa75633edfa98fae5433b9ec41b329 Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 11 Dec 2020 14:30:16 +0000 Subject: [PATCH 06/12] special king clothes --- tests/frontend/specs/scrollTo.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/frontend/specs/scrollTo.js b/tests/frontend/specs/scrollTo.js index 7509cec1bb7..05489cf2aaa 100755 --- a/tests/frontend/specs/scrollTo.js +++ b/tests/frontend/specs/scrollTo.js @@ -10,7 +10,6 @@ describe('scrolls to line', function () { this.timeout(10000); }); - it('Scrolls down to Line 4', function (done) { this.timeout(10000); const chrome$ = helper.padChrome$; @@ -22,3 +21,25 @@ describe('scrolls to line', function () { done(); }); }); + +describe('doesnt break on weird hash input', function () { + // create a new pad with URL hash set before each test run + beforeEach(function (cb) { + helper.newPad({ + hash: '#DEEZ123123NUTS', + cb, + }); + this.timeout(10000); + }); + + it('Does NOT change scroll', function (done) { + this.timeout(10000); + const chrome$ = helper.padChrome$; + helper.waitFor(() => { + const topOffset = parseInt(chrome$('iframe').first('iframe') + .contents().find('#outerdocbody').css('top')); + return (!topOffset); // no css top should be set. + }); + done(); + }); +}); From 7440dd15fc7084ba5759f4116bc2fbf26bc81dbe Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 11 Dec 2020 14:32:52 +0000 Subject: [PATCH 07/12] docs? --- doc/api/embed_parameters.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/api/embed_parameters.md b/doc/api/embed_parameters.md index 79b60f2140e..d6f27af0556 100644 --- a/doc/api/embed_parameters.md +++ b/doc/api/embed_parameters.md @@ -3,10 +3,10 @@ You can easily embed your etherpad-lite into any webpage by using iframes. You c Example: -Cut and paste the following code into any webpage to embed a pad. The parameters below will hide the chat and the line numbers. +Cut and paste the following code into any webpage to embed a pad. The parameters below will hide the chat and the line numbers and will auto-focus on Line 4. ``` - + ``` ## showLineNumbers @@ -66,3 +66,10 @@ Example: `lang=ar` (translates the interface into Arabic) Default: true Displays pad text from right to left. +## #L + * Int + +Default: 0 +Focuses pad at specific line number and places caret at beginning of this line +Special note: Is not a URL parameter but instead of a Hash value + From 114656cd846d9152beb85156f70f548cac9af338 Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 11 Dec 2020 19:02:55 +0000 Subject: [PATCH 08/12] working in both mobile and normal view --- src/static/js/pad_editor.js | 105 +++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index e918ded6d39..74b285f64e6 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -41,54 +41,17 @@ const padeditor = (function () { function aceReady() { $('#editorloadingbox').hide(); - const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); if (readyFunc) { - // If a number is in the URI IE #L124 go to that line number - const lineNumber = window.location.hash.substr(1); - if (lineNumber) { - if (lineNumber[0] === 'L') { - const lineNumberInt = parseInt(lineNumber.replace('L', '')); - if (lineNumberInt) { - const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') - .contents().find('#innerdocbody'); - const line = $inner.find(`div:nth-child(${lineNumberInt})`); - if (line.length !== 0) { - let offsetTop = line.offset().top; - offsetTop += parseInt($outerdoc.css('padding-top').replace('px', '')); - offsetTop += parseInt($inner.css('padding-top').replace('px', '')); - const $outerdocHTML = $('iframe[name="ace_outer"]').contents() - .find('#outerdocbody').parent(); - $outerdoc.css({top: `${offsetTop}px`}); // Chrome - $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF - const node = line[0]; - self.ace.callWithAce((ace) => { - const selection = { - startPoint: { - index: 0, - focusAtStart: true, - maxIndex: 1, - node, - }, - endPoint: { - index: 0, - focusAtStart: true, - maxIndex: 1, - node, - }, - }; - ace.ace_setSelection(selection); - }); - } - } - } - } + readyFunc(); + // Listen for clicks on sidediv items + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); $outerdoc.find('#sidedivinner').on('click', 'div', function () { const targetLineNumber = $(this).index() + 1; window.location.hash = `L${targetLineNumber}`; }); - readyFunc(); + exports.focusOnLine(self.ace); } } @@ -100,11 +63,10 @@ const padeditor = (function () { } self.initViewOptions(); self.setViewOptions(initialViewOptions); - // view bar $('#viewbarcontents').show(); }, - initViewOptions() { + initViewOptions: () => { // Line numbers padutils.bindCheckboxChange($('#options-linenoscheck'), () => { pad.changeViewOption('showLineNumbers', padutils.getCheckbox($('#options-linenoscheck'))); @@ -121,8 +83,8 @@ const padeditor = (function () { pad.changeViewOption('rtlIsTrue', padutils.getCheckbox($('#options-rtlcheck'))); }); html10n.bind('localized', () => { - pad.changeViewOption('rtlIsTrue', ('rtl' == html10n.getDirection())); - padutils.setCheckbox($('#options-rtlcheck'), ('rtl' == html10n.getDirection())); + pad.changeViewOption('rtlIsTrue', ('rtl' === html10n.getDirection())); + padutils.setCheckbox($('#options-rtlcheck'), ('rtl' === html10n.getDirection())); }); // font family change @@ -134,9 +96,9 @@ const padeditor = (function () { html10n.bind('localized', () => { $('#languagemenu').val(html10n.getLanguage()); // translate the value of 'unnamed' and 'Enter your name' textboxes in the userlist - // this does not interfere with html10n's normal value-setting because html10n just ingores s - // also, a value which has been set by the user will be not overwritten since a user-edited - // does *not* have the editempty-class + // this does not interfere with html10n's normal value-setting because html10n + // just ingores s also, a value which has been set by the user will be not + // overwritten since a user-edited does *not* have the editempty-class $('input[data-l10n-id]').each((key, input) => { input = $(input); if (input.hasClass('editempty')) { @@ -210,3 +172,50 @@ const padeditor = (function () { }()); exports.padeditor = padeditor; + +exports.focusOnLine = (ace) => { + // If a number is in the URI IE #L124 go to that line number + const lineNumber = window.location.hash.substr(1); + if (lineNumber) { + if (lineNumber[0] === 'L') { + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); + const lineNumberInt = parseInt(lineNumber.replace('L', '')); + if (lineNumberInt) { + const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') + .contents().find('#innerdocbody'); + const line = $inner.find(`div:nth-child(${lineNumberInt})`); + if (line.length !== 0) { + let offsetTop = line.offset().top; + offsetTop += parseInt($outerdoc.css('padding-top').replace('px', '')); + const hasMobileLayout = $('body').hasClass('mobile-layout'); + if (!hasMobileLayout) { + offsetTop += parseInt($inner.css('padding-top').replace('px', '')); + } + const $outerdocHTML = $('iframe[name="ace_outer"]').contents() + .find('#outerdocbody').parent(); + $outerdoc.css({top: `${offsetTop}px`}); // Chrome + $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + const node = line[0]; + ace.callWithAce((ace) => { + const selection = { + startPoint: { + index: 0, + focusAtStart: true, + maxIndex: 1, + node, + }, + endPoint: { + index: 0, + focusAtStart: true, + maxIndex: 1, + node, + }, + }; + ace.ace_setSelection(selection); + }); + } + } + } + } + // End of setSelection / set Y position of editor +}; From 7fe37cd49c52e223e4906e5beb73d736186ad94e Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 11 Dec 2020 19:06:07 +0000 Subject: [PATCH 09/12] linting --- src/static/js/pad_editor.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index 74b285f64e6..db5ee3bef1f 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -109,23 +109,23 @@ const padeditor = (function () { $('#languagemenu').val(html10n.getLanguage()); $('#languagemenu').change(() => { Cookies.set('language', $('#languagemenu').val()); - window.html10n.localize([$("#languagemenu").val(), 'en']); + window.html10n.localize([$('#languagemenu').val(), 'en']); if ($('select').niceSelect) { $('select').niceSelect('update'); } }); }, - setViewOptions(newOptions) { - function getOption(key, defaultValue) { + setViewOptions: (newOptions) => { + const getOption = (key, defaultValue) => { const value = String(newOptions[key]); - if (value == 'true') return true; - if (value == 'false') return false; + if (value === 'true') return true; + if (value === 'false') return false; return defaultValue; - } + }; let v; - v = getOption('rtlIsTrue', ('rtl' == html10n.getDirection())); + v = getOption('rtlIsTrue', ('rtl' === html10n.getDirection())); self.ace.setProperty('rtlIsTrue', v); padutils.setCheckbox($('#options-rtlcheck'), v); @@ -146,24 +146,24 @@ const padeditor = (function () { self.ace.setProperty('textface', newOptions.padFontFamily || ''); }, - dispose() { + dispose: () => { if (self.ace) { self.ace.destroy(); self.ace = null; } }, - enable() { + enable: () => { if (self.ace) { self.ace.setEditable(true); } }, - disable() { + disable: () => { if (self.ace) { self.ace.setProperty('grayedOut', true); self.ace.setEditable(false); } }, - restoreRevisionText(dataFromServer) { + restoreRevisionText: (dataFromServer) => { pad.addHistoricalAuthors(dataFromServer.historicalAuthorData); self.ace.importAText(dataFromServer.atext, dataFromServer.apool, true); }, From 801f94eecad9ee02a57054310dba4418222922a5 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 26 Dec 2020 13:13:04 +0000 Subject: [PATCH 10/12] fix up tests --- tests/frontend/specs/scrollTo.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/frontend/specs/scrollTo.js b/tests/frontend/specs/scrollTo.js index 05489cf2aaa..8ec3071c3d9 100755 --- a/tests/frontend/specs/scrollTo.js +++ b/tests/frontend/specs/scrollTo.js @@ -10,15 +10,14 @@ describe('scrolls to line', function () { this.timeout(10000); }); - it('Scrolls down to Line 4', function (done) { + it('Scrolls down to Line 4', async function () { this.timeout(10000); const chrome$ = helper.padChrome$; - helper.waitFor(() => { + await helper.waitFor(() => { const topOffset = parseInt(chrome$('iframe').first('iframe') .contents().find('#outerdocbody').css('top')); return (topOffset >= 100); }); - done(); }); }); @@ -32,14 +31,13 @@ describe('doesnt break on weird hash input', function () { this.timeout(10000); }); - it('Does NOT change scroll', function (done) { + it('Does NOT change scroll', async function () { this.timeout(10000); const chrome$ = helper.padChrome$; - helper.waitFor(() => { + await helper.waitFor(() => { const topOffset = parseInt(chrome$('iframe').first('iframe') .contents().find('#outerdocbody').css('top')); return (!topOffset); // no css top should be set. }); - done(); }); }); From b85c3477b7d181bd45584a56bbb80b5002dfa404 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sat, 26 Dec 2020 14:33:32 +0100 Subject: [PATCH 11/12] scrollTo test: waitFor -> waitForPromise --- tests/frontend/specs/scrollTo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/frontend/specs/scrollTo.js b/tests/frontend/specs/scrollTo.js index 8ec3071c3d9..47fe1ca7ef0 100755 --- a/tests/frontend/specs/scrollTo.js +++ b/tests/frontend/specs/scrollTo.js @@ -13,7 +13,7 @@ describe('scrolls to line', function () { it('Scrolls down to Line 4', async function () { this.timeout(10000); const chrome$ = helper.padChrome$; - await helper.waitFor(() => { + await helper.waitForPromise(() => { const topOffset = parseInt(chrome$('iframe').first('iframe') .contents().find('#outerdocbody').css('top')); return (topOffset >= 100); @@ -34,7 +34,7 @@ describe('doesnt break on weird hash input', function () { it('Does NOT change scroll', async function () { this.timeout(10000); const chrome$ = helper.padChrome$; - await helper.waitFor(() => { + await helper.waitForPromise(() => { const topOffset = parseInt(chrome$('iframe').first('iframe') .contents().find('#outerdocbody').css('top')); return (!topOffset); // no css top should be set. From 6eb90fc9f0af6f689b64f2ef7d7b28fe94f0be28 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sat, 26 Dec 2020 21:46:49 +0100 Subject: [PATCH 12/12] replace replace with substr for readability --- src/static/js/pad_editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index 101161219d3..70afc0e09d2 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -181,7 +181,7 @@ exports.focusOnLine = (ace) => { if (lineNumber) { if (lineNumber[0] === 'L') { const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); - const lineNumberInt = parseInt(lineNumber.replace('L', '')); + const lineNumberInt = parseInt(lineNumber.substr(1)); if (lineNumberInt) { const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') .contents().find('#innerdocbody');