summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <none@none>2012-11-10 15:53:29 +0100
committerportix <none@none>2012-11-10 15:53:29 +0100
commit1f16bf084a48700c8184617d0d5fad7f071f63d6 (patch)
tree880f9a7fbf177b45a693cb0b03621700cb6dad8a
parent826df17aa118f08cfb1cc00fa1c66036d15a53ca (diff)
downloaddwb-1f16bf084a48700c8184617d0d5fad7f071f63d6.zip
Paste primary selection into webview
-rw-r--r--scripts/base.js68
-rw-r--r--src/callback.c2
-rw-r--r--src/dwb.c20
3 files changed, 44 insertions, 46 deletions
diff --git a/scripts/base.js b/scripts/base.js
index 32dd6bbb..f6a10237 100644
--- a/scripts/base.js
+++ b/scripts/base.js
@@ -662,50 +662,66 @@ Object.freeze((function () {
globals.bigFont = Math.ceil(font.replace(/\D/g, "") * 1.25) + "px";
globals.fontSize = Math.ceil(font.replace(/\D/g, ""))/2;
};
-
-
-
+ var __pastePrimary = function(primary) {
+ var a = document.activeElement;
+ if (a instanceof HTMLInputElement || a instanceof HTMLTextAreaElement) {
+ var start = a.selectionStart;
+ a.value = a.value.substring(0, start) + primary + a.value.substring(a.selectionEnd);
+ a.selectionStart = a.selectionEnd = start + primary.length;
+ }
+ else if (a.isContentEditable)
+ {
+ var selection = window.getSelection();
+ var range = selection.getRangeAt(0);
+ selection.removeAllRanges();
+ range.insertNode(document.createTextNode(primary));
+ range.collapse(false);
+ selection.addRange(range);
+ }
+ };
return {
createStyleSheet : function() {
__createStyleSheet(document);
},
showHints : function(obj) {
- return __showHints(obj.type, obj.newTab);
- },
+ return __showHints(obj.type, obj.newTab);
+ },
updateHints : function (obj) {
- return __updateHints(obj.input, obj.type);
- },
+ return __updateHints(obj.input, obj.type);
+ },
clear : function () {
- __clear();
- },
+ __clear();
+ },
followActive : function (obj) {
- return __evaluate(__getActive().element, obj.type);
- },
-
+ return __evaluate(__getActive().element, obj.type);
+ },
focusNext : function () {
- __focusNext();
- },
+ __focusNext();
+ },
focusPrev : function () {
- __focusPrev();
- },
+ __focusPrev();
+ },
addSearchEngine : function () {
- return __addSearchEngine();
- },
+ return __addSearchEngine();
+ },
submitSearchEngine : function (obj) {
- return __submitSearchEngine(obj.searchString);
- },
+ return __submitSearchEngine(obj.searchString);
+ },
focusInput : function () {
- __focusInput();
- },
+ __focusInput();
+ },
+ pastePrimary : function(selection) {
+ __pastePrimary(selection);
+ },
insertAdblockRule : function(rule) {
var st=document.createElement('style');
document.head.appendChild(st);
document.styleSheets[document.styleSheets.length-1].insertRule(rule, 0);
},
init : function (obj) {
- __init(obj.hintLetterSeq, obj.hintFont, obj.hintStyle, obj.hintFgColor,
- obj.hintBgColor, obj.hintActiveColor, obj.hintNormalColor,
- obj.hintBorder, obj.hintOpacity, obj.hintHighlighLinks, obj.hintAutoFollow);
- }
+ __init(obj.hintLetterSeq, obj.hintFont, obj.hintStyle, obj.hintFgColor,
+ obj.hintBgColor, obj.hintActiveColor, obj.hintNormalColor,
+ obj.hintBorder, obj.hintOpacity, obj.hintHighlighLinks, obj.hintAutoFollow);
+ }
};
})());
diff --git a/src/callback.c b/src/callback.c
index 321e1991..91e2bdaa 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -167,12 +167,10 @@ callback_key_press(GtkWidget *w, GdkEventKey *e) {
dwb_change_mode(NORMAL_MODE, true);
ret = false;
}
-#if 0
else if(e->state == GDK_SHIFT_MASK && e->keyval == GDK_KEY_Insert) {
dwb_paste_primary();
return true;
}
-#endif
else if (dwb_eval_override_key(e, CP_OVERRIDE_ALL))
ret = true;
else if (mode & INSERT_MODE) {
diff --git a/src/dwb.c b/src/dwb.c
index 4c2a14e0..8d10cf87 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -804,33 +804,17 @@ dwb_set_clipboard(const char *text, GdkAtom atom) {
return ret;
}/*}}}*/
-#if 0
void
dwb_paste_primary() {
- char *c_text = NULL;
GtkClipboard *p_clip = gtk_widget_get_clipboard(CURRENT_WEBVIEW_WIDGET(), GDK_SELECTION_PRIMARY);
if (p_clip == NULL)
return;
char *p_text = gtk_clipboard_wait_for_text(p_clip);
- if (p_text == NULL)
- return;
- GtkClipboard *c_clip = gtk_widget_get_clipboard(CURRENT_WEBVIEW_WIDGET(), GDK_NONE);
- if (c_clip == NULL)
- return;
- c_text = gtk_clipboard_wait_for_text(c_clip);
- gtk_clipboard_set_text(c_clip, p_text, -1);
- webkit_web_view_paste_clipboard(CURRENT_WEBVIEW());
- if (c_clip != NULL) {
- if (c_text != NULL)
- gtk_clipboard_set_text(c_clip, c_text, -1);
- else {
- // clear clipboard
- }
+ if (p_text != NULL) {
+ js_call_as_function(FOCUSED_FRAME(), CURRENT_VIEW()->js_base, "pastePrimary", p_text, kJSTypeString, NULL);
}
g_free(p_text);
- g_free(c_text);
}
-#endif
/* dwb_scroll (Glist *gl, double step, ScrollDirection dir) {{{*/
void