11use std:: process:: Command ;
2+ use crate :: config:: internal_clipboard;
23use super :: * ;
34
45const TMP_PATH : & str = "/tmp/hop-clipboard.txt" ;
@@ -17,6 +18,11 @@ impl Tab {
1718 }
1819 }
1920
21+ if internal_clipboard ( ) {
22+ self . internal_clipboard = text;
23+ return ;
24+ }
25+
2026 if let Err ( error) = fs:: write ( TMP_PATH , text) {
2127 confirm ! ( "failed to write clipboard-file ({TMP_PATH}):\n {error:?}" ) ;
2228 return ;
@@ -31,14 +37,19 @@ impl Tab {
3137 }
3238
3339 pub fn paste ( & mut self ) {
34- try_exec ( false ) ;
40+ let mut text = take ( & mut self . internal_clipboard ) ;
41+ let cursors = self . cursors . len ( ) ;
3542
36- let Ok ( text) = fs:: read_to_string ( TMP_PATH ) else {
37- confirm ! ( "failed to read clipboard-file ({TMP_PATH})" ) ;
38- return ;
39- } ;
43+ if !internal_clipboard ( ) {
44+ try_exec ( false ) ;
4045
41- let cursors = self . cursors . len ( ) ;
46+ let Ok ( contents) = fs:: read_to_string ( TMP_PATH ) else {
47+ confirm ! ( "failed to read clipboard-file ({TMP_PATH})" ) ;
48+ return ;
49+ } ;
50+
51+ text = contents;
52+ }
4253
4354 if cursors > 1 {
4455 let regions = text. split ( DELIMITER ) . count ( ) ;
@@ -106,6 +117,8 @@ fn try_exec(copy: bool) {
106117
107118 if !success {
108119 let ln1 = "failed to use wl-clipboard, xclip or macOS equivalents." ;
109- confirm ! ( "{ln1}\n please make sure at least one of these works." ) ;
120+ let ln2 = "please make sure at least one of these works." ;
121+ let ln3 = "alternatively, set `internal-clipboard` to `true` in config." ;
122+ confirm ! ( "{ln1}\n {ln2}\n {ln3}" ) ;
110123 }
111124}
0 commit comments