Răsfoiți Sursa

wallet: enable PASTAH

darkfi 1 an în urmă
părinte
comite
6bc57f25c0

+ 1 - 31
bin/darkwallet/src/app/schema/chat.rs

@@ -44,7 +44,7 @@ use crate::{
         emoji_picker, Button, ChatEdit, ChatView, EditBox, EmojiPicker, Image, Layer, ShapeVertex,
         Shortcut, Text, VectorArt, VectorShape, Window,
     },
-    util::unixtime,
+    util::{unixtime, Clipboard},
     ExecutorPtr,
 };
 
@@ -174,36 +174,6 @@ mod ui_consts {
 use super::EMOJI_PICKER_ICON_SIZE;
 use ui_consts::*;
 
-struct Clipboard {
-    #[cfg(not(target_os = "android"))]
-    clip: arboard::Clipboard,
-}
-
-impl Clipboard {
-    fn new() -> Self {
-        Self {
-            #[cfg(not(target_os = "android"))]
-            clip: arboard::Clipboard::new().unwrap(),
-        }
-    }
-
-    fn get(&mut self) -> Option<String> {
-        #[cfg(target_os = "android")]
-        return miniquad::window::clipboard_get();
-
-        #[cfg(not(target_os = "android"))]
-        return self.clip.get_text().ok();
-    }
-
-    fn set(&mut self, data: &str) {
-        #[cfg(target_os = "android")]
-        return miniquad::window::clipboard_set(data);
-
-        #[cfg(not(target_os = "android"))]
-        return self.clip.set_text(data).unwrap();
-    }
-}
-
 fn android_keyboard_height() -> f32 {
     #[cfg(target_os = "android")]
     return crate::android::get_keyboard_height() as f32;

+ 13 - 5
bin/darkwallet/src/ui/chatedit.rs

@@ -48,7 +48,7 @@ use crate::{
     pubsub::Subscription,
     scene::{MethodCallSub, Pimpl, SceneNodePtr, SceneNodeWeak},
     text::{self, Glyph, GlyphPositionIter, TextShaperPtr},
-    util::{enumerate_ref, is_whitespace, min_f32, unixtime, zip4},
+    util::{enumerate_ref, is_whitespace, min_f32, unixtime, zip4, Clipboard},
     ExecutorPtr,
 };
 
@@ -1151,8 +1151,9 @@ impl ChatEdit {
             }
             'v' => {
                 if mods.ctrl {
-                    if let Some(text) = window::clipboard_get() {
-                        //self.paste_text(text).await;
+                    let mut clip = Clipboard::new();
+                    if let Some(text) = clip.get() {
+                        self.insert_text(&text).await;
                     }
                     return true
                 }
@@ -2010,12 +2011,19 @@ impl UIObject for ChatEdit {
             return false
         }
 
+        let rect = self.rect.get();
+
         if btn != MouseButton::Left {
+            if btn == MouseButton::Right && rect.contains(mouse_pos) {
+                if self.text.get().is_empty() {
+                    let node = self.node.upgrade().unwrap();
+                    node.trigger("paste_request", vec![]).await.unwrap();
+                }
+                return true
+            }
             return false
         }
 
-        let rect = self.rect.get();
-
         if !rect.contains(mouse_pos) {
             return false
         }

+ 3 - 0
bin/darkwallet/src/util.rs → bin/darkwallet/src/util/mod.rs

@@ -19,6 +19,9 @@
 use colored::Colorize;
 use std::time::{SystemTime, UNIX_EPOCH};
 
+mod clip;
+pub use clip::Clipboard;
+
 pub fn is_whitespace(s: &str) -> bool {
     s.chars().all(char::is_whitespace)
 }