From 158a12c9d07902695c1edf15538a9941682c82c9 Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 18 Dec 2013 21:51:21 +0000 Subject: [PATCH] make it so focus is drawn to new location on page break --- package.json | 2 +- static/js/page_view.js | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9cb4708..798f491 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ep_page_view", - "version": "0.4.6", + "version": "0.4.7", "keywords": ["page view", "pv", "preview", "overview", "page break", "break", "new page"], "description": "Add support to do 'page view', with a toggle on/off option in Settings, also Page Breaks with Control Enter", "contributors": [ diff --git a/static/js/page_view.js b/static/js/page_view.js index 566bf3d..bbc1f8b 100644 --- a/static/js/page_view.js +++ b/static/js/page_view.js @@ -140,21 +140,43 @@ exports.aceCreateDomLine = function(name, context){ function doInsertPageBreak(){ this.editorInfo.ace_doReturnKey(); + console.log("THIS WITH REP", this); var rep = this.rep; var documentAttributeManager = this.documentAttributeManager; if (!(rep.selStart && rep.selEnd)){ return; } // only continue if we have some caret position var firstLine = rep.selStart[0]; // Get the first line var lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0)); // Get the last line - _(_.range(firstLine, lastLine + 1)).each(function(i){ // For each line, either turn on or off task list + _(_.range(firstLine, lastLine + 1)).each(function(i){ // For each line, either turn on or off page break var isPageBreak = documentAttributeManager.getAttributeOnLine(i, 'pageBreak'); if(!isPageBreak){ // if its already a PageBreak item - documentAttributeManager.setAttributeOnLine(i, 'pageBreak', 'pageBreak'); // make the line a task list + documentAttributeManager.setAttributeOnLine(i, 'pageBreak', 'pageBreak'); // make the line a page break }else{ - documentAttributeManager.removeAttributeOnLine(i, 'pageBreak'); // remove the task list from the line + documentAttributeManager.removeAttributeOnLine(i, 'pageBreak'); // remove the page break from the line } }); + + // Get caret focus this.editorInfo.ace_focus(); + + // Insert a line this.editorInfo.ace_doReturnKey(); + + // Get the document + var document = this.editorInfo.ace_getDocument(); + + // Update the selection from the rep + this.editorInfo.ace_updateBrowserSelectionFromRep(); + + // Get the current selection + var myselection = document.getSelection(); + + // Get the selections top offset + var caretOffsetTop = myselection.focusNode.offsetTop; + + // Move to the new Y co-ord to bring the new page into focus + $('iframe[name="ace_outer"]').contents().find('#outerdocbody').scrollTop(caretOffsetTop-120); // Works in Chrome + $('iframe[name="ace_outer"]').contents().find('#outerdocbody').parent().scrollTop(caretOffsetTop-120); // Works in Firefox + // Sighs } // Once ace is initialized, we set ace_doInsertPageBreak and bind it to the context