Browse Source

Undo, Redo, and Paste are handled properly from the editor menu bar.

Shaddock Heath 9 years ago
parent
commit
b0df467662

+ 0 - 1
Script/AtomicEditor/ui/Shortcuts.ts

@@ -168,7 +168,6 @@ class Shortcuts extends Atomic.ScriptObject {
         if (!ToolCore.toolSystem.project) return;
         var resourceFrame = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
         if (resourceFrame) {
-            resourceFrame.setFocus();
             resourceFrame.invokeShortcut(shortcut);
         }
     }

+ 12 - 35
Script/AtomicWebViewEditor/editor/editorCommands.ts

@@ -161,39 +161,16 @@ export function setEditor(editor: any) {
 export function invokeShortcut(shortcut: Editor.EditorShortcutType) {
 
     const ed = internalEditor.getInternalEditor();
-    // Execute in the next cycle
-    window.setTimeout(() => {
-
-        ed.focus();
-        switch (shortcut) {
-            case "cut":
-            case "copy":
-            case "undo":
-            case "redo":
-                window.document.execCommand(shortcut);
-                break;
-
-            case "selectall":
-                ed.setSelection(ed.getModel().getFullModelRange());
-                break;
-        }
-    }, 100);
-
-
-    /*
-case "undo":
-    cmd = ed["cursor"]["_handlers"]["undo"];
-    ed.executeCommand("Atomic", cmd);
-    break;
-    //ed.executeCommand("Atomic", ))
-    // ed.executeCommand("Atomic", "undo");
-case "redo":
-    cmd = ed["cursor"]["_handlers"]["redo"];
-    ed.executeCommand("Atomic", cmd);
-    break;
-    */
-    //const sel = ed.getSelection();
-    //if (!sel.isEmpty()) {
-    //const s = ed.getModel().getValueInRange(sel);
-    //}
+    ed.focus();
+    switch (shortcut) {
+        case "cut":
+        case "copy":
+        case "paste":
+            window.document.execCommand(shortcut);
+            break;
+
+        case "selectall":
+            ed.setSelection(ed.getModel().getFullModelRange());
+            break;
+    }
 }

+ 25 - 11
Source/AtomicEditor/Editors/JSResourceEditor.cpp

@@ -177,24 +177,38 @@ bool JSResourceEditor::OnEvent(const TBWidgetEvent &ev)
         if (ev.ref_id == TBIDC("close"))
         {
             RequestClose();
-        } else if (ev.ref_id == TBIDC("paste")) {
-            // Paste needs to be handled here due to permissions in the web client that don't allow paste to be called from JavaScript.
-            // The others can be passed directly to the editor and be handled there
-            webClient_->SendFocusEvent(true);
-            webClient_->ShortcutPaste();
         } else if (ev.ref_id == TBIDC("undo")) {
-            webClient_->SendFocusEvent(true);
-            webClient_->ShortcutUndo();
+            // Need to physically send the CTRL/CMD+Z to the browser so that
+            // the internal editor responds appropriately.  The browser UNDO doesn't fire off
+            // the right events inside the editor.
+            VariantMap map;
+            map[KeyUp::P_KEY] = KEY_Z;
+            map[KeyUp::P_SCANCODE] = SCANCODE_Z;
+            #ifdef ATOMIC_PLATFORM_OSX
+            map["ForceSuperDown"] = true;
+            #else
+            map[KeyUp::P_QUALIFIERS] = QUAL_CTRL;
+            #endif
+            webClient_->SendKeyEvent( StringHash("KeyDown"), map);
         } else if (ev.ref_id == TBIDC("redo")) {
-            webClient_->SendFocusEvent(true);
-            webClient_->ShortcutRedo();
+            // Need to physically send the CTRL/CMD+SHIFT+Z to the browser so that
+            // the internal editor responds appropriately.  The browser REDO doesn't fire off
+            // the right events inside the editor.
+            VariantMap map;
+            map[KeyUp::P_KEY] = KEY_Z;
+            map[KeyUp::P_SCANCODE] = SCANCODE_Z;
+            #ifdef ATOMIC_PLATFORM_OSX
+            map[KeyUp::P_QUALIFIERS] = QUAL_SHIFT;
+            map["ForceSuperDown"] = true;
+            #else
+            map[KeyUp::P_QUALIFIERS] = QUAL_SHIFT | QUAL_CTRL;
+            #endif
+            webClient_->SendKeyEvent( StringHash("KeyDown"), map);
         } else {
             String shortcut;
             UI* ui = GetSubsystem<UI>();
             ui->GetTBIDString(ev.ref_id, shortcut);
 
-            webClient_->SendFocusEvent();
-            //webClient_->SendKeyEvent(Atomicjkb);
             webClient_->ExecuteJavaScript(ToString("HOST_invokeShortcut(\"%s\");", shortcut.CString()));
         }
     }

+ 2 - 0
Source/AtomicWebView/WebClient.cpp

@@ -353,6 +353,8 @@ public:
         browserSettings.file_access_from_file_urls = STATE_ENABLED;
         browserSettings.universal_access_from_file_urls = STATE_ENABLED;
         browserSettings.web_security = WebBrowserHost::GetWebSecurity() ? STATE_ENABLED : STATE_DISABLED;
+        browserSettings.javascript_access_clipboard = STATE_ENABLED;
+        browserSettings.javascript_dom_paste = STATE_ENABLED;
 
         windowInfo.width = width;
         windowInfo.height = height;