* @param {string} url Absolute URL to where the plugin is located.\r
*/\r
init : function(ed) {\r
- var t = this;\r
+ var t = this, lastRng;\r
\r
t.editor = ed;\r
\r
\r
ed.onContextMenu.add(function(ed, e) {\r
if (!e.ctrlKey) {\r
+ // Restore the last selection since it was removed\r
+ if (lastRng)\r
+ ed.selection.setRng(lastRng);\r
+\r
t._getMenu(ed).showMenu(e.clientX, e.clientY);\r
- Event.add(ed.getDoc(), 'click', hide);\r
+ Event.add(ed.getDoc(), 'click', function(e) {\r
+ hide(ed, e);\r
+ });\r
Event.cancel(e);\r
}\r
});\r
\r
- function hide() {\r
+ ed.onRemove.add(function() {\r
+ if (t._menu)\r
+ t._menu.removeAll();\r
+ });\r
+\r
+ function hide(ed, e) {\r
+ lastRng = null;\r
+\r
+ // Since the contextmenu event moves\r
+ // the selection we need to store it away\r
+ if (e && e.button == 2) {\r
+ lastRng = ed.selection.getRng();\r
+ return;\r
+ }\r
+\r
if (t._menu) {\r
t._menu.removeAll();\r
t._menu.destroy();\r