editor/ux: Clearauthorship on full doc selected

pull/4075/head
John McLear 2020-06-05 22:47:12 +01:00 committed by GitHub
parent d4fcc23fb3
commit 6dbfe5e43c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 1 deletions

View File

@ -484,7 +484,27 @@ var padeditbar = (function()
}); });
toolbar.registerAceCommand("clearauthorship", function (cmd, ace) { 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"))) { if (window.confirm(html10n.get("pad.editbar.clearcolors"))) {
ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [ ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [
['author', ''] ['author', '']