Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to share and/or copy into the clipboard dictionary definitions. #9336

Closed
YashaNoos opened this issue Jul 15, 2022 · 23 comments
Closed
Labels
enhancement User patch available Request is odd, specific, or complicated to do properly - but a user patch is provided

Comments

@YashaNoos
Copy link

I'm using a space repetition system (anki) to build my English vocabulary while reading novel and I need to have the possibility to copy or share word's definitions into anki in order to create new cards. After searching for sometimes I was unable to find a way to grab the content of the built in dictionary's window.

Ideally, I would like to have a share or copy button within the dictionary window if possible.
I'm still learning how to use Koreader efficiently and if I missed the solution somewhere I'm sorry.

By the way, if it matters, I'm on Android. And really congratulation on the work done, it's the best reader I have used so far and I have tried MANY.

@Frenzie
Copy link
Member

Frenzie commented Jul 15, 2022

On Android you can also easily use any other dictionary app btw, if that makes the workflow easier.

@YashaNoos
Copy link
Author

I have for a period of time used a dictionary outside of Koreader but it was painfully slow and clunky, I use an Onyx boox e-reader and those are not optimize for multitasking at all.
My "procedure" was :
select a word->
copy->
slide down the notification tab where an instance of my dictionary app is running->
tap on the "translate" button, the dictionary app would launch using whatever is in the clipboard as a query->
select the whole definition text (sometimes it would glitch with the selection cursor getting stuck for some reason, leading to me restarting the whole thing again. ) ->
And at last sharing to anki.

I quickly grew tired of my procedure, that's why the built in dictionary system in Koreader is so valuable to me, it's quick and doesn't need to transition to a third app. If only I could copy or share directly the content of the definition window it would be perfect.

@Frenzie
Copy link
Member

Frenzie commented Jul 15, 2022

I was referring rather to if you go to dictionary settings (find icon in the top menu), you can pick one (or define your own, that's detailed in the wiki somewhere):

Screenshot_2022-07-15-21-29-41-92_1aff61e6bd981aaa4ba9d0245eb6c04f

@poire-z
Copy link
Contributor

poire-z commented Jul 15, 2022

As we're short of place for more buttons, and as the use case is quite specific, you could help yourself with a User patch (available in next stable, or current nightlies).

Download 2-dict-auto-copy-current-definition.lua.txt , remove the .txt extension, and drop it in koreader/patches/ (create this patches/ directory manually).
Its content:

local Device = require("device")
local DictQuickLookup = require("ui/widget/dictquicklookup")

local changeDictionary_orig = DictQuickLookup.changeDictionary
DictQuickLookup.changeDictionary = function(self, index, skip_update)
    changeDictionary_orig(self, index, skip_update)
    local text = self.displayword .. "\n" .. self.definition -- tweak this if needed
    Device.input.setClipboardText(text)
end

Any definition you see would be copied to clipboard (so, the last one replaces the previous one), and up to you to paste it or not into other apps.
(No idea if HTML content will be fine, or if you would need to clean it, but there is already code for that somewhere.)

@YashaNoos
Copy link
Author

Oh yes I see, I have tried some of those but still ran into problems like fora would not format the text properly or look up sharing fonction would create its own card format in anki....

@YashaNoos
Copy link
Author

As we're short of place for more buttons, and as the use case is quite specific, you could help yourself with a User patch (available in next stable, or current nightlies).

Download 2-dict-auto-copy-current-definition.lua.txt , remove the .txt extension, and drop it in koreader/patches/ (create this patches/ directory manually). Its content:

local Device = require("device")
local DictQuickLookup = require("ui/widget/dictquicklookup")

local changeDictionary_orig = DictQuickLookup.changeDictionary
DictQuickLookup.changeDictionary = function(self, index, skip_update)
    changeDictionary_orig(self, index, skip_update)
    local text = self.displayword .. "\n" .. self.definition -- tweak this if needed
    Device.input.setClipboardText(text)
end

Any definition you see would be copied to clipboard (so, the last one replaces the previous one), and up to you to paste it or not into other apps. (No idea if HTML content will be fine, or if you would need to clean it, but there is already code for that somewhere.)

I'm gonna try that right now thank you!

@YashaNoos
Copy link
Author

It seems that the built in dictionary doesn't work anymore when I switch from stable to development.
Stable
firefox_m5UPGEQFb5
Development
firefox_1nINxjRWHU

I will wait for the stable to test it out :p

@poire-z
Copy link
Contributor

poire-z commented Jul 15, 2022

Might not yet be solved in nest stable :/ See #9296 or #8255, or some other one I can't find.
May be try to remove/fresh-install instead of update, I think I've read somewhere doing that may help/

@YashaNoos
Copy link
Author

I will give it a try! But I'm a bit of a n00b here I was able to find the [2022.06] release but not the 2022.06000038 :/

@mergen3107
Copy link
Contributor

@YashaNoos
You might have a look here: http://build.koreader.rocks/download/nightly/

It has directories with most recent nightlies, go to appropriate directory and download for your OS, the same as for releases in Github

@YashaNoos
Copy link
Author

YashaNoos commented Jul 15, 2022

Thank you!

Well still unable to use the built in dictionary system using 2022.06000038 on a clean install, works perfectly on 2022.06. I'm just gonna be patient :)
Thank to everyone for your help!

@poire-z
Copy link
Contributor

poire-z commented Jul 15, 2022

You could try the apk in this zip:
https://gitlab.com/koreader/nightly-builds/-/jobs/2642515761/artifacts/download?file_type=archive
It's the last build before the sdcv (stardict binary) update, but includes the "user patch" thing.

@YashaNoos
Copy link
Author

For some reason this apk can't install on my e reader:/
GnUpRVtnE

@mergen3107
Copy link
Contributor

@YashaNoos
That’s probably either due to (1) your current install is newer, or (2) those apks have different signatures, so a complete uninstall could help

@mergen3107
Copy link
Contributor

Your KOReader settings should stay as long as you keep /sdcard/koreader/ directory intact between installs/uninstalls

@YashaNoos
Copy link
Author

YashaNoos commented Jul 16, 2022

Thanks for your help but even after a complete uninstall this apk (2022.06-7) refuse to install. I have tried other nightlies all install without any trouble but the dictionary problem remain though.

@Frenzie
Copy link
Member

Frenzie commented Jul 16, 2022

Raw GitLab builds are unsigned. To install them you'd need to sign them.

Android is terrible in this regard and it only gives you reasons for errors over ADB.

Anyway, I triggered a build with #9340 so in an hour the latest nightly will have a working dictionary on Android.

@YashaNoos
Copy link
Author

I'll try it and give feed back as soon I can. Really impressed by everyone reactivity!

@YashaNoos
Copy link
Author

I just tried v2022.06-39 and not only the dictionary work perfectly now, but @poire-z patch works exactly as intended!
image
Anki as no problem handling HTML, I just need to clean up the "query" stuff but its really minor:p
It's so much easier to create card quickly and just keep reading.
Thanks to everyone again it was such a quick and efficient response!

@poire-z poire-z added the User patch available Request is odd, specific, or complicated to do properly - but a user patch is provided label Jul 16, 2022
@poire-z poire-z closed this as completed Jul 16, 2022
@gebuhtigi
Copy link

Since the latest KOReader update, 2-dict-auto-copy-current-definition.lua seems to no longer function. Translations are now the only things that get automatically copied to the clipboard, and that happens regardless of the patch's presence. Does anyone happen to know what needs to be updated to get it working again?

..I'm terrible with lua patching...

@poire-z
Copy link
Contributor

poire-z commented Jun 9, 2023

Seems to still work for me, on the emulator. Tested by doing and reading some lookup results, then closing all going into Dict lookup menu to do a manual lookup, and long-press in the input field to see the clipboard content:
image
Does that work or not for you (so we know if it's the internal clipboard, or passing the internal clipboard => your device clipboard for pasting into other apps)?
What's your device, and previous working KOReader version, and current non-working version?

@gebuhtigi
Copy link

  • Device 1 (main daily e-reader): Onyx Boox Poke 3 --- Android 10 --- was v2022.11 before issue, currently v2023.04
  • Device 2: Boox Poke 5 --- Android 11 --- v2023.04
  • Device 3: Samsung Galaxy S9 --- Android 10 --- v2022.07
  • Device 4: Samsung Galaxy S23 --- Android 13 --- tested v2023.04 and v2023.05.1
  • Device 5: Microsoft Surface Duo --- Android 11 --- tested v2022.11
  • Device 6: Meebook M6 --- Android 11 --- tested v2022.07
    Devices 1-3 had the patch working before it didn't. After testing out a few other devices and KOReader versions, I'm not even sure it's because of the KOReader update anymore. It's just strange that it happened all at the same time, and to even my old S9 that I never even updated...

Long-pressing on the Dictionary Lookup after defining one word will show "(empty)":
Screenshot_20230611214305

After that, it'll pull up whatever is latest on my Android clipboard at the time, including clips from other apps. Whenever I translate a phrase, a toast saying "Copied to Clipboard!" pops up, and that'd be the phrase in the Clipboard for Dictionary Lookup.
Screenshot_20230611051625

Screen_Recording_20230611_051534.mp4

When I changed the gesture setting for "Long-press on text" to just "Translate", then sure enough, the single word gets translated, and also gets copied to the system clipboard.

So it seems KOReader can still successfully copy to the system clipboard and retrieve data from it (all the copy buttons work as expected too). It's just for some reason, it seems the translator is "stealing" this auto-copy action from the patch. Maybe there's a way to override this auto-copy on translate feature, so it can apply to the dictionary word instead? (For my use case, I didn't need the definition, just the word itself, so I removed the definition part in the lua patch. Whenever I can't conjure a mental association between a word and its definition in KOReader, I'd open up an Aard2 floating window and view the Wiktionary etymology for it.)

@poire-z
Copy link
Contributor

poire-z commented Jun 12, 2023

Well, no idea.
The user patch does the same thing that the translator does (I don't think we want it done auto for dict lookups, the fact it exists for translation is just chance, #7855).

You could try to display some notification in the user patch between each step, to see if it fails at some point, and display at the end what was put into the clipboard.

local Device = require("device")
local DictQuickLookup = require("ui/widget/dictquicklookup")
local Notification = require("ui/widget/notification")

local changeDictionary_orig = DictQuickLookup.changeDictionary
DictQuickLookup.changeDictionary = function(self, index, skip_update)
    Notification:notify("step 1", Notification.SOURCE_DISPATCHER)
    changeDictionary_orig(self, index, skip_update)
    Notification:notify("step 2", Notification.SOURCE_DISPATCHER)
    local text = self.displayword .. "\n" .. self.definition
    Notification:notify("step 3", Notification.SOURCE_DISPATCHER)
    Notification:notify(text, Notification.SOURCE_DISPATCHER)
    Device.input.setClipboardText(text)
    Notification:notify("step 4", Notification.SOURCE_DISPATCHER)
    Notification:notify(Device.input.getClipboardText(), Notification.SOURCE_DISPATCHER)
end

and you could see:
image
(no worry if long text seems truncated/messy, Notification is single line and not made to handle long text.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement User patch available Request is odd, specific, or complicated to do properly - but a user patch is provided
Projects
None yet
Development

No branches or pull requests

5 participants