=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java' --- src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/WebClientMessageTypes.java 2015-10-14 15:17:43 +0000 @@ -159,4 +159,7 @@ /** Resizeable widget. */ public static final byte SET_RESIZEABLE_WINDOW = (byte) 0x9A; + + /** Notifies the client about the current selection. */ + public static final byte MSG_CURRENT_SELECTION = (byte) 0x9B; } === modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js 2015-10-14 13:46:19 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js 2015-10-14 16:21:44 +0000 @@ -22,6 +22,7 @@ ** the web which had a typo because I can find no evidence it is a real ** thing). Added cut event support. Added base implementation to respond to ** GUI processing, there are still open issues. +** 005 SBI 20151014 Implemented to set the current editors selection. */ "use strict"; @@ -165,9 +166,7 @@ var text = p2j.clipboard_helpers.getSelectedText(); // copy selection to clipboard - inputText.value = encodeURIComponent(text); // to escape "\n" - inputText.focus(); - inputText.select(); + setSelection(text); } }; @@ -232,19 +231,29 @@ */ me.writeClipboard = function(text) { - // copy selection to clipboard + //in order to get the last selection snapshot we set the value of clipboard to the current selection. + setSelection(text); + //TODO: find a way to arbitrarily write the contents of the clipboard on non-IE + if (window.clipboardData) + { + window.clipboardData.clearData(); + window.clipboardData.setData("Text", text); + } + }; + + me.setSelection = setSelection; + /** + * Sets the current selection. + * + * @param {String} text + * The selected text, current selection. + */ + function setSelection(text) + { inputText.value = encodeURIComponent(text); // to escape "\n" inputText.focus(); inputText.select(); -// TODO: find a way to arbitrarily write the contents of the clipboard on non-IE -// if (window.clipboardData) -// { -// console.log("window.clipboardData"); -// window.clipboardData.clearData(); -// window.clipboardData.setData("Text", text); -// } - }; - + } /** * Check if a string is empty. * === modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js 2015-10-14 14:40:28 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js 2015-10-14 15:31:57 +0000 @@ -26,7 +26,8 @@ ** processing is intended to be compatible with WinKeyboardReader, though ** it may not yet be 100% correct. ** 010 SBI 20151006 GUI rewrite to support better key processing compatibility. -** 011 SBI 20151014 Auto-repeats are fixed. +** 011 SBI 20151014 Auto-repeats are fixed. Added GUI copy/cut/paste alternative keys support +** that used by clipboard processing. */ "use strict"; @@ -506,7 +507,7 @@ return; } else if (last.key === evt.keyCode) - { + { // auto-repeats that have no typed keys. last = { key : evt.keyCode, shift : evt.shiftKey, === modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2015-10-14 16:23:14 +0000 @@ -28,7 +28,8 @@ ** in the wrong order. Added mouse support. Create font returns the font's ** index in the local font-table. ** 011 CA 20150925 Added explicit track of widget z-order. -** 012 CA 20151013 Added support for window resize for the GUI web client. +** 012 CA 20151013 Added support for window resize for the GUI web client, added to set +** the current editors selection. */ "use strict"; @@ -422,7 +423,7 @@ p2j.clipboard.sendClipboardContents(); break; case 0x88: - // server response for selected text + // The clipboard is changed. var text = me.readStringBinaryMessage(message, 1); p2j.clipboard.writeClipboard(text); break; @@ -843,6 +844,11 @@ } break; + case 0x9B: + // current editors selection is changed + var text = me.readStringBinaryMessage(message, 1); + p2j.clipboard.setSelection(text); + break; }; } else === modified file 'src/com/goldencode/p2j/ui/client/gui/EditorGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/EditorGuiImpl.java 2015-10-14 14:40:28 +0000 +++ src/com/goldencode/p2j/ui/client/gui/EditorGuiImpl.java 2015-10-14 16:25:02 +0000 @@ -25,6 +25,7 @@ ** GuiDriver: all access to the driver is done exclusively, each thread taking ** and releasing ownership for the duration of the drawing operation or other ** GUI API invocation which requires access to the underlying physical window. +** 011 SBI 20151014 Added to notify the client the current selection is changed. */ package com.goldencode.p2j.ui.client.gui; === modified file 'src/com/goldencode/p2j/ui/client/gui/FillInGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/FillInGuiImpl.java 2015-10-14 14:40:28 +0000 +++ src/com/goldencode/p2j/ui/client/gui/FillInGuiImpl.java 2015-10-14 16:25:45 +0000 @@ -39,6 +39,7 @@ ** GuiDriver: all access to the driver is done exclusively, each thread taking ** and releasing ownership for the duration of the drawing operation or other ** GUI API invocation which requires access to the underlying physical window. +** 020 SBI 20151014 Added to notify the client the current selection is changed. */ package com.goldencode.p2j.ui.client.gui; === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2015-10-14 14:40:28 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2015-10-14 15:46:50 +0000 @@ -1208,14 +1208,14 @@ } /** - * Sets the current selection. + * Sets the current editors selection. * * @param txt - * The current selection. + * The current editors selection. */ @Override public void setCurrentSelection(String txt) { - copyToClipboard(txt); + websock.setSelection(txt); } } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2015-10-14 13:46:19 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2015-10-14 15:44:36 +0000 @@ -913,11 +913,11 @@ } /** - * Writes to the current selection to the application clipboard and notify the JS client - * about the current selection. + * Copies the given text to the application clipboard and notifies the JS client + * about the current clipboards content. * * @param text - * The current selection. + * The current clipboard content. */ public void writeClipboard(String text) { @@ -1919,6 +1919,17 @@ } /** + * Notifies the JS client that the current editors selection is changed. + * + * @param text + * The current editors selection. + */ + public void setSelection(String text) + { + sendBinaryMessage(MSG_CURRENT_SELECTION, (text == null) ? "" : text); + } + + /** * Allocate a new byte array of the proper size, add it to the pending operations list and * set the message byte. *