From 1464098b5906ed47e833722f3f30c9e2bd1fff5d Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 14 May 2023 12:45:50 +0800 Subject: [PATCH] add delete to input context menu --- app/scripts/controllers/new.js | 12 ++++++++++++ app/scripts/core/root.js | 5 +++++ app/scripts/directives/setting.js | 2 +- app/views/new.html | 2 +- app/views/setting.html | 7 +++++-- main/components/menu.js | 18 ++++++++++++++++++ 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/scripts/controllers/new.js b/app/scripts/controllers/new.js index 5094b10..c725c18 100644 --- a/app/scripts/controllers/new.js +++ b/app/scripts/controllers/new.js @@ -748,6 +748,18 @@ }; }; + $scope.isSupportForceDeleteEmpty = function (option) { + if ($scope.context.options[option.key] || $scope.context.options[option.key] === '') { + return false; + } + + if (option.overrideMode === 'append' || aria2SettingService.isOptionKeyRequired(option.key)) { + return false; + } + + return !!($scope.context.globalOptions[option.key] && $scope.context.globalOptions[option.key].trim()); + }; + $scope.setOption = function (key, value, optionStatus) { if (value !== '' || !aria2SettingService.isOptionKeyRequired(key)) { $scope.context.options[key] = value; diff --git a/app/scripts/core/root.js b/app/scripts/core/root.js index 2e51a19..4cbde0e 100644 --- a/app/scripts/core/root.js +++ b/app/scripts/core/root.js @@ -650,6 +650,11 @@ context.editable = false; } + if (angular.element(event.target).attr('data-support-force-delete-empty') === 'true' + && angular.element(event.target).val() === '') { + context.forceDeleteEmpty = true; + } + if (event.target.nodeName.match(/^(input|textarea)$/i) || event.target.isContentEditable) { ariaNgNativeElectronService.showTextboxContextMenu(context); } diff --git a/app/scripts/directives/setting.js b/app/scripts/directives/setting.js index 6698d1c..95be902 100644 --- a/app/scripts/directives/setting.js +++ b/app/scripts/directives/setting.js @@ -12,13 +12,13 @@ ngModel: '=', defaultValue: '=?', fixedValue: '=?', + supportForceDeleteEmpty: '=?', onChangeValue: '&' }, link: function (scope, element, attrs, ngModel) { var pendingSaveRequest = null; var options = { showPlaceholderCount: false, - deleteKeyAlwaysChangeValue: false, lazySaveTimeout: ariaNgConstants.lazySaveTimeout, errorTooltipPlacement: 'top', errorTooltipDelay: ariaNgConstants.errorTooltipDelay diff --git a/app/views/new.html b/app/views/new.html index cd4f897..d8e5de8 100644 --- a/app/views/new.html +++ b/app/views/new.html @@ -222,7 +222,7 @@

-                
                 
-                
diff --git a/main/components/menu.js b/main/components/menu.js
index f1922ff..30fa932 100644
--- a/main/components/menu.js
+++ b/main/components/menu.js
@@ -138,6 +138,20 @@ let buildTextboxContextMenu = function(context) {
             }
         }
 
+        if (item.role === 'delete') {
+            if (context.forceDeleteEmpty) {
+                item.role = '';
+                item.click = function () {
+                    core.mainWindow.webContents.sendInputEvent({
+                        type: 'keyUp',
+                        keyCode: 'Delete'
+                    });
+                }
+            } else if (context.selected === false) {
+                item.enabled = false;
+            }
+        }
+
         if (item.role === 'undo' || item.role === 'redo' || item.role === 'cut' || item.role === 'paste') {
             if (context.editable === false) {
                 item.enabled = false;
@@ -195,6 +209,10 @@ let setTextboxContextMenuTemplate = function (context) {
             label: getMenuTitle(context, 'Paste', 'Paste'),
             role: 'paste'
         },
+        {
+            label: getMenuTitle(context, 'Delete', 'Delete'),
+            role: 'delete'
+        },
         {
             type: 'separator'
         },