If you copy the text I provided in the link below and paste it into a text editor (I tried several ones: gedit
, notepad
, phpstorm
, but also command-line editors like nano
) you will experience difficulties.
http://pastebin.com/5dqT7mFm
Here are a few I noticed during my tests:
I also noticed, that those problems will not occur, if I enable the text-wrap
functionality in the respective text editor.
What I would like to know is, why text editors have this kind of problems with long lines? Is there a reasonable explanation for this behavior?
It is a very good way of storing text information, but it has no way of handling more involved formatting. Text editors generally do not allow you to do things like change font sizes or styles, spell checking, or columns.
Pressing ALT+{up,down} moves the complete lines (not just the selection) up and down, fixing indentation as you go. Hitting CTRL+D deletes the lines completely (not just the selection) without leaving any unwanted blank lines.
A text editor is computer software used for editing plain text. It is distinguished from a word processor because it does not manage document formatting or other features commonly used in desktop publishing.
What I would like to know is, why text editors have this kind of problems with long lines? Is there a reasonable explanation for this behavior?
I'm the author of the Zeus IDE so I'll give my take on why this is the case.
One major reason is the existence of the tab character. Let me explain.
Because the text editor must assume the line might contain tab characters, the only way it can properly handle those tabs is to parse the line from left to right, always starting at the first character of the line.
To understand why, consider these two lines of code where ^ represents the tab character:
This is line one with no tables
This line has a ^ tab character
If the tab size is 8 this will need to be drawn like this:
This is line one with no tables
This line has a tab character
If the tab size is 4 it will drawn like this:
This is line one with no tables
This line has a tab character
But the length of both those lines is exactly the same at 31 characters.
So to draw the line correctly the editor had to parse the line left to right, always starting at the first character of the line.
Naturally for long lines this drawing can be slow.
Now consider this second case where the | character represents the cursor:
This is line one with no |tables
This line has a tab character
In the case above the cursor is at index position 25 in the line, which also represents cursor position 25 on the screen (as the line contains no tabs).
Now let’s assume the user moves the cursor down one line as shown below:
This is line one with no tables
This line has a |tab character
Now the cursor is still at cursor screen position 25 but because of the 8 character tab that represents the index 18 location for that line.
To figure this out the editor needed to run a calculation on the line checking for tabs along the way and once again for long lines this takes time.
These are just two examples of the index to cursor, cursor to index mappings that need to be done by the editor.
Those same calculations will also be needed for keyboard events, mouse clicks, text marking, text cut/copy and paste etc etc.
I also noticed, that those problems will not occur, if I enable the text-wrap functionality in the respective text editor.
When you turn on text-wrap you have effectively taken one long line and made it into many shorter lines and that in turn speeds up the tab calculations mentioned earlier.
PS: Zeus did handle your 286,721 character line, but like most editors it does not respond well to a file with that length of line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With