Recent

Author Topic: Copying Code examples from forum brings line numbers  (Read 2092 times)

jamie

  • Hero Member
  • *****
  • Posts: 6090
Copying Code examples from forum brings line numbers
« on: July 06, 2019, 05:56:05 pm »
I use IE, maybe that is an issue but, when I select all of even use the option SELECT, all text except
the numbers are selected, I copy it, then I paste it within the code window of laz but, all the line numbers
come with it..

 It does not matter If I paste in NotePad, the line numbers are still there.

 What do you guys do to eliminate that issue ?
The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Copying Code examples from forum brings line numbers
« Reply #1 on: July 06, 2019, 06:03:51 pm »
I use Pluma text editor. It will replace the line numbers with spaces but I still have to manually clean up the spaces.

Luckily if I paste it to Lazarus source editor, all of the line numbers will be removed properly. In this case, Lazarus is smarter than any text editor I ever knew.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Copying Code examples from forum brings line numbers
« Reply #2 on: July 06, 2019, 06:21:10 pm »
Use another browser...

You can try to fix the script, but it needs to keep working under other browsers. (You can get it from your browsers debugger)
Tested with (by copying to notepad++)
Win10: Firefox, Chrome, Edge
Win Vista: Opera, Safari

And I do not plan to repeatedly test new attempts on fixing it. If you believe you have a working version, I will test it (once) and update if it works.

And it also must be completely in the onclick tag of the link. I do not have access to modify other stuff.
(That means it should not grow to much in size, since it repeats with every code block on the page)

----------------
If you have a solution that needs bigger changes you can post it. I can try to get the attention of the server admin. But he is a very busy person....

---------EDIT
Actually IIRC making it work (back then) was changing the display options of GESHI. I spent quite some hours testing...

Anyway code is displayed using GESHI extension.
And the JS is a modified copy of what the forum used before.
« Last Edit: July 06, 2019, 06:24:34 pm by Martin_fr »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Copying Code examples from forum brings line numbers
« Reply #3 on: July 06, 2019, 08:08:43 pm »
Sounds like too much work to fix the forums,. I'll write a utility to remove the leading line numbers and
have it hook into the clipboard monitor chain to clean it up automatically.

 Thanks for the info..
 
 I guess I could offer it up to the public when done but it will only work on windows, I don't know how to
do this in Linux.
The only true wisdom is knowing you know nothing

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Copying Code examples from forum brings line numbers
« Reply #4 on: July 06, 2019, 08:34:01 pm »
Luckily if I paste it to Lazarus source editor, all of the line numbers will be removed properly. In this case, Lazarus is smarter than any text editor I ever knew.
That is really interesting.  When I paste it into the Lazarus source editor, I get the line numbers.

Does anyone know if removing the lines numbers is a "user selectable" option in Lazarus and is it a feature available in Lazarus 1.8.2 or does it require a later version ?

Thanks.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Copying Code examples from forum brings line numbers
« Reply #5 on: July 06, 2019, 08:44:11 pm »
Did anybody try to uncheck "Toggle View" above the forum editor or to uncheck the option "Show WYSIWIG editor by default" in the forum profile? When this feature is not active copy & paste between forum posts works fine for me, no line numbers when pasting source code. I can't say anything about line numbers when pasting into the IDE because I never observed this issue.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Copying Code examples from forum brings line numbers
« Reply #6 on: July 06, 2019, 09:37:34 pm »
An other workaround: Quote the post and copy the code from the reply box.

(I use Firefox and didn't encounter the described issue before.)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Copying Code examples from forum brings line numbers
« Reply #7 on: July 06, 2019, 09:46:40 pm »
I tested it again, these are what I found:

Copying code example from forum to Lazarus source editor didn't have any line number issue.

Copying code example from forum to Pluma text editor, sometimes it replaces the line number with spaces but usually it automatically removes the line numbers correctly. Hmmm, need to inspect more.

Copying code example from forum to forum (post reply), it has line number issue. But as wp mentioned, if the toggle view disabled, no line number issue.

I'm using Lazarus 2.0.2 Linux GTK2, Pale Moon 28.6.01 web browser and Pluma 1.20.4 text editor.

Below is the screenshot:
pasted to Lazarus Source Editor  ---  original code in Pale Moon browser  ---  pasted to Pluma
« Last Edit: July 06, 2019, 09:50:04 pm by Handoko »

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Copying Code examples from forum brings line numbers
« Reply #8 on: July 06, 2019, 09:57:11 pm »
Quick solution:
Mark the spaces or numbers as a rectangular block in Notepad++ or Lazarus and delete them.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Copying Code examples from forum brings line numbers
« Reply #9 on: July 06, 2019, 10:39:17 pm »

For some reason (likely because I'm not doing something right), so far, I have not been able to get the code without the line numbers.


@wp

My "Show WYSIWYG editor on post page by default. " is off/unchecked.

Did anybody try to uncheck "Toggle View" above the forum editor
I don't see a "Toggle View" anywhere ... did I miss an elephant in the room again ?



@kupferstecher

An other workaround: Quote the post and copy the code from the reply box.

(I use Firefox and didn't encounter the described issue before.)
Unless something else works, I'll be using that.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Copying Code examples from forum brings line numbers
« Reply #10 on: July 06, 2019, 10:47:17 pm »
I don't see a "Toggle View" anywhere ... did I miss an elephant in the room again ?
It's the last button, "[arrow]", in the second button row, below the "Change color" combo.

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Copying Code examples from forum brings line numbers
« Reply #11 on: July 06, 2019, 10:59:53 pm »
I don't see a "Toggle View" anywhere ... did I miss an elephant in the room again ?
It's the last button, "[arrow]", in the second button row, below the "Change color" combo.
Thank you.  I tried and I got the message "Your browser does not support Rich Text Editing".  I guess I am out of luck with that one.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Copying Code examples from forum brings line numbers
« Reply #12 on: July 06, 2019, 11:07:06 pm »
I just wrote up a simple app that hooks into the clipboard and I was able to filter out the line numbers

This is the code block that did the actual editing of it.
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.WmDrawClipBoard(Var M:Tmessage);
  2. Var
  3.   L,X:Integer;
  4.   S:String;
  5. Begin
  6.   SendMessage(NextClipBoardHandle,M.Msg,M.wParam,m.Lparam); //Pass it on..
  7.   If ClipBoard.HasFormat(CF_Text) Then
  8.   Begin
  9.    SynEdit1.Lines.Text :=  ClipBoard.AsText;
  10.    {Delete lines with nothing on them,only empty lines with numbers are valid }
  11.    For L := SynEdit1.Lines.Count-1 DownTo 0 do
  12.     if SynEdit1.Lines[L]='' Then SynEdit1.Lines.Delete(L);
  13.    For L := 0 to  SynEdit1.Lines.Count-1 do
  14.     Begin
  15.       S := SynEdit1.Lines[L];
  16.       X := 1;
  17.       While (X <= Length(S))and(S[X] in ['0'..'9','.']) Do Inc(X);
  18.       S := Copy(S,X,Length(S));
  19.       SynEdit1.Lines[L] := S;
  20.     end;
  21. end;
  22. End;                                              
  23.  
The next step is deciding if I should put the corrected version back on the clipboard automatically or
use a button for this.. Hmm.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Copying Code examples from forum brings line numbers
« Reply #13 on: July 06, 2019, 11:50:31 pm »
This is the first time I've posted a publish project but here goes.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018