Paste as plain text

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
SemiKebab
Moonbather
Moonbather
Posts: 50
Joined: 2021-05-30, 03:48

Re: Paste as plain text

Unread post by SemiKebab » 2024-01-12, 07:44

I often use the "paste as plain text" feature in programs such as text editors, and consider it to be very useful (I even consider that this feature should be mandatory),
but I don't see how it can be useful in web browsers, where we usually paste into text inputs that already convert the data to plain text?

(actually, in a browser "copy as plain text" would make more sense, but that feature would be very unusual…)

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-12, 15:31

SemiKebab wrote:
2024-01-12, 07:44
, where we usually paste into text inputs that already convert the data to plain text?
It is not always so. Modern WYSIWYG editors are built around a container element (say a DIV) with the "contenteditable" attribute set. You can paste HTML there. And then there is a difference between "paste" and "paste as plain text".
For example, https://www.tiny.cloud/

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-12, 15:40

By the way, if someone needs, for the sake of generality, the keyboard shortcut CTRL+SHIFT+V to work for the <textarea> element, which only supports plain text, then this can be done here by adding the appropriate line:
https://repo.palemoon.org/MoonchildProd ... s-base.inc

Code: Select all

<handler event="keypress" key="v" modifiers="accel,shift" command="cmd_paste"/>

SemiKebab
Moonbather
Moonbather
Posts: 50
Joined: 2021-05-30, 03:48

Re: Paste as plain text

Unread post by SemiKebab » 2024-01-12, 16:09

Kris_88 wrote:
2024-01-12, 15:31
It is not always so. Modern WYSIWYG editors are built around a container element (say a DIV) with the "contenteditable" attribute set. You can paste HTML there. And then there is a difference between "paste" and "paste as plain text".
For example, https://www.tiny.cloud/
Good point about the WYSIWYG editors. I'm too used to avoid them the most possible, and use what is referred to as "classic editor" and such, as the "modern" editors are often an annoyance to me, and I prefer seeing and having control of the formatting code :P

User avatar
suzyne
Lunatic
Lunatic
Posts: 364
Joined: 2023-06-28, 22:43
Location: Australia

Re: Paste as plain text

Unread post by suzyne » 2024-01-12, 19:50

SemiKebab wrote:
2024-01-12, 07:44
I often use the "paste as plain text" feature in programs such as text editors, and consider it to be very useful (I even consider that this feature should be mandatory), but I don't see how it can be useful in web browsers
If you find pasting as plain text in programs useful, then it will be useful in a web browser, because it is not unusual for many webapps to default to getting the formatted text that is currently on the clipboard, and to ignore the plain text.

One example is GMail, when composing an email trying Ctrl+V or Crtl+Shift+V or Shift+Ins will always insert formatted text into my message which is rarely, if ever, what I want so I have PureText installed to get the behaviour that I need, without having to go through the nuisance of pasting into Notepad and copying back into GMail.

I imagine it could be said that since I can do what I want, then what's the problem? But not everyone is on Windows and so have option on installing PureText?

The other browsers I have tried all have a "Paste as plain text" command in the pop-up menu (with a keyboard shortcut of Crtl+Shift+V) and while I appreciate that Pale Moon is not trying to be like other browsers, the omission of that command always feels surprising.

I truly believe that this is a case where it could only benefit Pale Moon to include this feature of the other browsers.
Laptop 1: Windows 10 64-bit, i7 @ 2.80GHz, 16GB, NVIDIA GeForce MX450.
Laptop 2: Windows 10 32-bit, Atom Z3735F @ 1.33GHz, 2GB, Intel HD Graphics.

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-12, 21:19

suzyne wrote:
2024-01-12, 19:50
The other browsers I have tried all have a "Paste as plain text" command in the pop-up menu (with a keyboard shortcut of Crtl+Shift+V) and while I appreciate that Pale Moon is not trying to be like other browsers, the omission of that command always feels surprising.
If we add this command to the menu, the result will not change. The point is not how exactly this command is activated. What does the menu have to do with it if Gmail intercepts the event and chooses what to paste? It doesn't even try to respect the state of the Shift button. And why am I not surprised...

User avatar
RealityRipple
Astronaut
Astronaut
Posts: 666
Joined: 2018-05-17, 02:34
Location: Los Berros Canyon, California

Re: Paste as plain text

Unread post by RealityRipple » 2024-01-12, 21:23

Wow. The function already exists. "cmd_pasteNoFormatting"

https://realityripple.com/Software/XUL/papt/

The code is literally just:

Code: Select all

<menuitem id="context-pasteplain" class="menuitem-iconic" label="&papt.label;" accesskey="&papt.accesskey;" oncommand="goDoCommand('cmd_pasteNoFormatting');" insertafter="context-paste" />
and

Code: Select all

var papt =
{
 init: function()
 {
  const m = document.getElementById('context-pasteplain');
  if (m)
   m.hidden = true;
  document.getElementById('contentAreaContextMenu').addEventListener('popupshowing', papt.popup, false);
 },
 popup: function()
 {
  const controller = document.commandDispatcher.getControllerForCommand('cmd_pasteNoFormatting');
  const enabled = controller && controller.isCommandEnabled('cmd_pasteNoFormatting');
  const m = document.getElementById('context-pasteplain');
  if (m)
   m.hidden = !enabled;
 }
};
window.addEventListener('load', papt.init, false);

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-12, 21:26

RealityRipple wrote:
2024-01-12, 21:23
Wow. The function already exists. "cmd_pasteNoFormatting"
Not only does it exist, but it also works using CTRL+SHIFT+V.

User avatar
suzyne
Lunatic
Lunatic
Posts: 364
Joined: 2023-06-28, 22:43
Location: Australia

Re: Paste as plain text

Unread post by suzyne » 2024-01-12, 21:42

Kris_88 wrote:
2024-01-12, 21:19
What does the menu have to do with it if Gmail intercepts the event and chooses what to paste
I was only using GMail as one example, and anyway, in other browsers that have a "Paste as plain text" menu command, GMail manages to respect and do the requested action.
Moonchild wrote:
2024-01-09, 09:31
Off-topic:
BenFenner wrote:
2024-01-09, 00:37
I don't really care about non-power users and how confused they get.
Well, I do, and I have to.
Moonchild appears to care about the non-power user, and I think having what new users coming to Pale Moon think of as a standard basic feature, is a smart addition.

Especially when every other browser they have used has a "Paste as plain text" option in the pop-up menu that is very reliable at putting unformatted text into whatever type of area they are pasting into.

I don't understand the resistance to having a menu item so the non-power users can find the functionality they are expecting to see?
Laptop 1: Windows 10 64-bit, i7 @ 2.80GHz, 16GB, NVIDIA GeForce MX450.
Laptop 2: Windows 10 32-bit, Atom Z3735F @ 1.33GHz, 2GB, Intel HD Graphics.

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-12, 21:47

suzyne wrote:
2024-01-12, 21:42
I was only using GMail as one example, and anyway, in other browsers that have a "Paste as plain text" menu command, GMail manages to respect and do the requested action.
This needs to be explored - what does Gmail need to respect...
But in a normal situation the command works correctly. I gave an example, you can see for yourself...
viewtopic.php?f=5&t=30745#p247444

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-12, 21:58

By the way, look what Google itself brings up.
https://www.google.com/search?q=ctrl%2B ... ot+working

BenFenner
Astronaut
Astronaut
Posts: 588
Joined: 2015-06-01, 12:52
Location: US Southeast

Re: Paste as plain text

Unread post by BenFenner » 2024-01-12, 23:40

suzyne wrote:
2024-01-12, 21:42
Moonchild wrote:
2024-01-09, 09:31
Off-topic:
BenFenner wrote:
2024-01-09, 00:37
I don't really care about non-power users and how confused they get.
Well, I do, and I have to.
Moonchild appears to care about the non-power user
Of course he does, because of course Pale Moon as an entity should. I never said, nor implied otherwise. I was taken way out of context with that quote.
suzyne wrote:
2024-01-12, 21:42
and I think having what new users coming to Pale Moon think of as a standard basic feature, is a smart addition
Agreed, of course. (Assuming this meets that criteria.)
suzyne wrote:
2024-01-12, 21:42
I don't understand the resistance to having a menu item so the non-power users can find the functionality they are expecting to see?
No resistance here. We can all stop misquoting me now. :thumbup:

User avatar
suzyne
Lunatic
Lunatic
Posts: 364
Joined: 2023-06-28, 22:43
Location: Australia

Re: Paste as plain text

Unread post by suzyne » 2024-01-13, 01:15

BenFenner wrote:
2024-01-12, 23:40
We can all stop misquoting me now.
I wanted to quote Moonchild, but that wouldn't make any sense without your bit being pulled in as well.

I wasn't even thinking of any of your replies as I typed my last comment, but I am sorry for perpetuating you being misrepresented.
Laptop 1: Windows 10 64-bit, i7 @ 2.80GHz, 16GB, NVIDIA GeForce MX450.
Laptop 2: Windows 10 32-bit, Atom Z3735F @ 1.33GHz, 2GB, Intel HD Graphics.

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: Paste as plain text

Unread post by Kris_88 » 2024-01-13, 02:21

In short,

starting from FF54, the "clipboardData" property of a "paste" event contains a single text/plain element if the event is triggered by ctrl+shift+v. The changes affected quite a lot of files. If someone wants to look for the corresponding commit, then the key point is the appearance of the "PlainTextOnly" parameter in the CacheExternalClipboardFormats() function:

Code: Select all

void
DataTransfer::CacheExternalClipboardFormats(bool aPlainTextOnly)   
https://repo.palemoon.org/MoonchildProd ... .cpp#L1394

In previous versions of FF, the "clipboardData" property also contains HTML data (if it was in the clipboard).
I think this is the root cause of the problem. But there is no short solution. There are quite a lot of changes that need to be added carefully.

I used this file for testing.

Code: Select all

<html>
<body>
<div class="editor"style="float:left; width:400px; min-height:200px; background:#ffc0c0" contenteditable ></div>

<script>
const target = document.querySelector("div.editor");

target.addEventListener("paste", (event) => {
  event.preventDefault();

  let transf = (event.clipboardData || window.clipboardData);

  var s = '';
  for(var i=0; i<transf.types.length; i++) {
    s += transf.types[i] + ' = ' + transf.getData(transf.types[i]) + '\n';
  };

  alert(s);

});

</script>


</body>
</html>

User avatar
athenian200
Contributing developer
Contributing developer
Posts: 1537
Joined: 2018-10-28, 19:56
Location: Georgia

Re: Paste as plain text

Unread post by athenian200 » 2024-01-13, 08:03

suzyne wrote:
2024-01-12, 21:42
Moonchild appears to care about the non-power user, and I think having what new users coming to Pale Moon think of as a standard basic feature, is a smart addition.

Especially when every other browser they have used has a "Paste as plain text" option in the pop-up menu that is very reliable at putting unformatted text into whatever type of area they are pasting into.

I don't understand the resistance to having a menu item so the non-power users can find the functionality they are expecting to see?
Does a non-power user even know the difference between "plain text" and the regular paste feature? That sounds pretty advanced to me. I think that might be where MC is coming from as well, if I understand correctly.

It kinda sounds to me like we are talking about adding convenience features to the browser that would be used by people who have been using computers for a long time and are tired of using tricks like the one I described with Notepad to strip off the formatting from text. Someone who knows the difference between just copying/pasting as a basic concept, and worrying over whether what they just pasted is plain ASCII/Unicode text is probably a somewhat advanced user.

Not to say I am dead set against adding it to the browser, in fact I'm sure there are a handful of situations where I would use it. But to my ears, it sounds like a feature for programmers and power users. That is to say, I'm reluctant to add it as a base feature precisely because I think it would mostly benefit people like me, and not so much average users. I mean, I've used it in Edge a couple of times myself already, so...

So with every feature request, we're forced to second-guess whether this is bad for the extension ecosystem, whether it could potentially just represent extra visual clutter for many users (especially since this one would be appearing in a common context menu rather than being tucked away in a settings dialog), etc. Plus, if we implement it, we probably also have to implement a way to turn it off, as I'm sure someone will complain about it being there and using extra pixels on their setup when they don't personally use it. That's where I think the hesitation comes from, it's certainly not that we can't see the use of it.

The improved Ctrl+Shift+V thing Kris is talking about from Firefox 54 would probably be safe to implement, though (assuming the work needed isn't extensive and could still apply to our codebase easily). It's fairly close to our fork point, wouldn't change the browser UI at all and would be fairly easy to write extensions against if we did add it in.
"The Athenians, however, represent the unity of these opposites; in them, mind or spirit has emerged from the Theban subjectivity without losing itself in the Spartan objectivity of ethical life. With the Athenians, the rights of the State and of the individual found as perfect a union as was possible at all at the level of the Greek spirit." -- Hegel's philosophy of Mind

BenFenner
Astronaut
Astronaut
Posts: 588
Joined: 2015-06-01, 12:52
Location: US Southeast

Re: Paste as plain text

Unread post by BenFenner » 2024-01-13, 17:22

You know, we could look at it from this angle...

The fact that there is a keyboard shortcut to perform this special paste action in Pale Moon already points to a different "issue".
Almost without exception, user actions that can be performed with the pointer (mouse) via UI menus or similar should also be possible via the keyboard navigation through keyboard shortcuts or at least some combination thereof. Note that even though moving and resizing a window is done 99.999% with the pointer, it can still be done with the keyboard. And likewise the inverse is true. If something can be accomplished via keyboard shortcut or keyboard menu navigation, it should also be possible with pointer/mouse UI navigation.
It is not the only reasoning, but it is best described as: all things should be possible with only a keyboard connected, or only a pointer device connected.

On the "mostly performed with the keyboard" side of things for example, [F12] (or [Ctrl+Shift+I] apparently) is used to toggle the Developer Tools. But, of course it has the menu counterpart in Tools → Developer Tools → Toggle Tools. Maybe the keyboard shortcut is used most, but of course there is a traditional menu option for the pointer. I'd say this is a strong argument to place "Paste as text" in the Edit menu. This way the action can be performed with the pointer (and the keyboard shortcut is discoverable!).

(Adding this capability to the right-click context menu is a different topic, and not one I'm getting into one way or the other with this post.)