From 6dbfe5e43c2a6fde875cd0c6687b2cdfdfac0ce6 Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 5 Jun 2020 22:47:12 +0100 Subject: [PATCH] editor/ux: Clearauthorship on full doc selected --- src/static/js/pad_editbar.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/static/js/pad_editbar.js b/src/static/js/pad_editbar.js index b06a2d36b..07ca5a22b 100644 --- a/src/static/js/pad_editbar.js +++ b/src/static/js/pad_editbar.js @@ -484,7 +484,27 @@ var padeditbar = (function() }); toolbar.registerAceCommand("clearauthorship", function (cmd, ace) { - if ((!(ace.ace_getRep().selStart && ace.ace_getRep().selEnd)) || ace.ace_isCaret()) { + // If we have the whole document selected IE control A has been hit + var rep = ace.ace_getRep(); + var lastChar = rep.lines.atIndex(rep.lines.length()-1).width-1; + var lastLineIndex = rep.lines.length()-1; + if(rep.selStart[0] === 0 && rep.selStart[1] === 0){ + // nesting intentionally here to make things readable + if(rep.selEnd[0] === lastLineIndex && rep.selEnd[1] === lastChar){ + var doPrompt = true; + } + } + /* + * NOTICE: This command isn't fired on Control Shift C. + * I intentionally didn't create duplicate code because if you are hitting + * Control Shift C we make the assumption you are a "power user" + * and as such we assume you don't need the prompt to bug you each time! + * This does make wonder if it's worth having a checkbox to avoid being + * prompted again but that's probably overkill for this contribution. + */ + + // if we don't have any text selected, we have a caret or we have already said to prompt + if ((!(rep.selStart && rep.selEnd)) || ace.ace_isCaret() || doPrompt) { if (window.confirm(html10n.get("pad.editbar.clearcolors"))) { ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [ ['author', '']