Skip to content

Commit

Permalink
Remove cursor position saving
Browse files Browse the repository at this point in the history
  • Loading branch information
sheabunge committed Jan 24, 2019
1 parent 697cefd commit 0a1b901
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
19 changes: 1 addition & 18 deletions js/edit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* global code_snippets_editor_atts */

window.code_snippets_editor = (function (CodeMirror, editor_atts) {
const snippet_form = document.getElementById('snippet-form');

const save_snippet_cb = (cm) => document.getElementById('save_snippet').click();

editor_atts['extraKeys'] = window.navigator.platform.match('Mac') ?
Expand All @@ -13,21 +11,6 @@ window.code_snippets_editor = (function (CodeMirror, editor_atts) {
document.querySelector('.editor-help-text').className += ' platform-mac';
}

const editor = CodeMirror.fromTextArea(document.getElementById('snippet_code'), editor_atts);

// set the cursor to the previous position
let matches = window.location.href.match(/[?&]cursor_line=(\d+)&cursor_ch=(\d+)/);
if (matches) {
editor.focus();
editor.setCursor({line: matches[1], ch: matches[2]});
}

// send the current cursor position to the next page
snippet_form.addEventListener('submit', () => {
const cursor = editor.getCursor();
snippet_form.insertAdjacentHTML('beforeend', `<input type="hidden" name="snippet_editor_cursor_line" value="${cursor.line}">`);
snippet_form.insertAdjacentHTML('beforeend', `<input type="hidden" name="snippet_editor_cursor_ch" value="${cursor.ch}">`);
});
return CodeMirror.fromTextArea(document.getElementById('snippet_code'), editor_atts);

return editor;
})(window.Code_Snippets_CodeMirror, code_snippets_editor_atts);
6 changes: 0 additions & 6 deletions php/admin-menus/class-edit-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,6 @@ private function save_posted_snippet() {
code_snippets()->get_menu_url( 'edit' )
);

if ( isset( $_POST['snippet_editor_cursor_line'], $_POST['snippet_editor_cursor_ch'] ) &&
is_numeric( $_POST['snippet_editor_cursor_line'] ) && is_numeric( $_POST['snippet_editor_cursor_ch'] ) ) {
$redirect_uri = add_query_arg( 'cursor_line', intval( $_POST['snippet_editor_cursor_line'] ), $redirect_uri );
$redirect_uri = add_query_arg( 'cursor_ch', intval( $_POST['snippet_editor_cursor_ch'] ), $redirect_uri );
}

wp_redirect( esc_url_raw( $redirect_uri ) );
exit;
}
Expand Down

0 comments on commit 0a1b901

Please sign in to comment.