MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Plugin to insert text at current cursor position (https://www.mobileread.com/forums/showthread.php?t=339023)

Turtle91 08-16-2021 03:23 PM

Quote:

Originally Posted by DiapDealer (Post 4146921)
That sounds an awful lot like the built-in clipboard history feature. :blink:




Wait....Wut??? :eek:


Please don't tell me I missed another function that Sigil does so well already.....




:rofl:

DNSB 08-16-2021 10:20 PM

On a Windows computer, pressing windows-V give you a history to paste from. This works in Sigil and most other programs.

KevinH 08-16-2021 10:32 PM

Or as DiapDealer said use Sigil's Edit/Paste From Clipboard History... menu item or key shortcut on any platform. You can highlight any clipboard history item to paste or use the delete key to remove it from the history.

DiapDealer 08-16-2021 10:50 PM

It also saves the history between Sigil sessions (the preference setting determines how many are saved between sessions)

fxp33 09-04-2021 07:25 AM

Pasting
 
Hi all,

Maybe far from the original post title, but as the conversation was on the pasting topic I continue here.

The process is:
  1. copy from a web page
  2. go to sigil
  3. ctrl+v
  4. choose plain text
  5. or choose html

Here is what I meant... in images: https://www.youtube.com/watch?v=NAXWuLJN3lI

Hope this helps
Cheers

KevinH 09-04-2021 08:53 AM

Just use PageEdit with Sigil. It will do exactly what you want.

Quote:

Originally Posted by fxp33 (Post 4151602)
Hi all,

Maybe far from the original post title, but as the conversation was on the pasting topic I continue here.

The process is:
  1. copy from a web page
  2. go to sigil
  3. ctrl+v
  4. choose plain text
  5. or choose html

Here is what I meant... in images: https://www.youtube.com/watch?v=NAXWuLJN3lI

Hope this helps
Cheers


fxp33 09-04-2021 01:21 PM

Quote:

Originally Posted by KevinH (Post 4151617)
Just use PageEdit with Sigil. It will do exactly what you want.

Well, using a 160Mo external editor was not my idea of a simple pasting option 😉

I hoped more for an addition of ten lines of code:

javascript
Code:

document.addEventListener('paste', function (evt) {
  document.getElementById("plain").textContent = evt.clipboardData.getData('text/plain');
  document.getElementById("html").textContent = evt.clipboardData.getData('text/html');
}

Python gtk
Code:

#!/usr/bin/env python
import gtk
print (gtk.Clipboard().wait_for_contents('text/html')).data


qt
Code:

void DropArea::paste()
{
    const QClipboard *clipboard = QApplication::clipboard();
    const QMimeData *mimeData = clipboard->mimeData();

    if (mimeData->hasImage()) {
        setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
    } else if (mimeData->hasHtml()) {
        setText(mimeData->html());
        setTextFormat(Qt::RichText);
    } else if (mimeData->hasText()) {
        setText(mimeData->text());
        setTextFormat(Qt::PlainText);
    } else {
        setText(tr("Cannot display data"));
    }


KevinH 09-04-2021 02:00 PM

Huh? That code exists in PageEdit and it can easily be launched and run. It is meant to be integrated into Sigil which has an easy way to launch it.

Sigil's CodeView editor is not a browser window and always pastes html/text as its base property since it is an xhtml code editor where copy and paste of code snippets are always done. Almost all copies made in CodeView typically includes html tags or partial html as text. You can not paste into a CodeView formatted rich text or images. You are confusing the target (a pure text code editor vs a browser like dom editor (Old BookView and PageEdit).

PageEdit is exactly like old Sigil's BookView and pasting formatted text into the PageEdit browser window is handled as you would expect.

Doitsu 09-04-2021 02:15 PM

1 Attachment(s)
@fxp33

If the feature is that important to you, why not use a plugin? The following code should do the trick:

Spoiler:
Code:

# -*- coding: utf-8 -*-
import sys
from PyQt5.Qt import QApplication

def run(bk):
    app = QApplication(sys.argv)
    clipboard = QApplication.clipboard()
    mime_data = clipboard.mimeData()
   
    if mime_data.hasHtml():
        app.clipboard().setText(mime_data.html())

    return 0

def main():
  print ("I reached main when I should not have\n")
  return -1

if __name__ == "__main__":
  sys.exit(main())



Just assign it one of the 10 plugin shortcuts and a corresponding keyboard shortcut, and you're good to go.

However, you might want to consider using PageEdit instead, because it'll significantly clean up the messy HTML code that some apps will copy to the clipboard.

fxp33 09-05-2021 12:09 PM

Quote:

Originally Posted by Doitsu (Post 4151675)
@fxp33
Just assign it one of the 10 plugin shortcuts and a corresponding keyboard shortcut, and you're good to go.

Hi Doitsu,

Yep, the plugin was my intention... and this is precisely why I was hoping I could get a hint on "how to insert text at cursor position" in this thread. I opened a lot of plugins to try and understand how to do that... 😉

Thanks a lot for packaging and rewriting the code into a plugin... And of course, I will indeed, check with pageEdit 👍

Best regards
François

fxp33 09-05-2021 12:37 PM

Quote:

Originally Posted by KevinH (Post 4151672)
Huh? That code exists in PageEdit and it can easily be launched and run. It is meant to be integrated into Sigil which has an easy way to launch it.

PageEdit is exactly like old Sigil's BookView and pasting formatted text into the PageEdit browser window is handled as you would expect.

Yes Kevin, I see that I can have:
  • raw text: with a paste in Sigil
  • original html: with all the code and classes (PageEdit ctrl+v)
  • structured text: linefeed are kept with p and br (PageEdit, Edit menu, paste, select "no")

What I can't figure out is why all the buttons from pageEdit have been added to Sigil (bald, italic, images, special caracters and even cut, paste) except this pasting option. PageEdit seems therefor very redundant to Sigil, and I find it to be a very big "plugin" for "just pasting".

But as you and Doitsu mentioned: it does not just paste, it cleans the code too when choosing "plain text" by adding "p" and "br". Which I understand is not just 10 lines of code.

Thanks for your reply, this helped me try new things with pageEdit. 👍
Regards
François

KevinH 09-05-2021 12:50 PM

PageEdit is not a plugin. It is separate editing program app that allows limited WYSIWYG editing similar to what the old BookView did in some ways. It can be easily launched from within Sigil by setting PageEdit as the External XHTML editor in Sigil's Preferences.


All times are GMT -4. The time now is 08:32 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.