Archived

This topic is now archived and is closed to further replies.

How to implement text editor???

This topic is 5582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose I am a beginner.(I''ve learnt programming for 2-3 years, but this question seems like what a beginner will ask.) Two years ago, when I learnt a bit of C programming, I started to wonder how are simple text editors(eg. Notepad) really implemented. Hearing people say Notepad cannot process files larger than 64kb, I thought it uses a large static char array with size 64kb. Is it true? What I really concern is that how does it handle insertion and deletion. If the chars are stored in a large array, insertion and deletion at the end of the document is not difficult, but how about insertion and deletion at the middle. Are the chars mvoed around very often or does it have other more clever ways to handle this? I said to myself try to find the answer by myself 2 years ago. Today I do not seem to find the answer, I hope all experienced programmers can tell me the answer. Even if you do not consider yourself as experienced programmer, disscusions on how to solve the problem using the best way is welcomed!

Share this post


Link to post
Share on other sites
Notepad is a bad example, if you are talking about console apps, which it seems that you do.

Notepad is built for a windows enviroment using components such as text boxes and etc.

Share this post


Link to post
Share on other sites
quote:
Original post by biovenger
Notepad is a bad example, if you are talking about console apps, which it seems that you do.

Notepad is built for a windows enviroment using components such as text boxes and etc.


The fact that notepad is just a textbox with some simple Windows functions doesn''t really change his question. In fact he probably knows that Notepad is just a Windows text box. Thanks to OOP a Visual Programmer can insert a text box without having to worry about how the text box actually accepts and gets rid of characters. Anyway I am not sure if notepad (read textboxes if you want) have any special methods for inserting and deleting characters. He may be right in the case of Notepad that it is just a large char array that holds 64KB (or 67108864 characters, I think). I do know that notepad is a simple text editor, meaning it doesn''t contain any special formatting codes that are inserted within the text itself. That is why many people use it for writing code to their programs with it.



Share this post


Link to post
Share on other sites
if you can dig out TurboVision by borland (used to ship with their dos c++/pascal compilers), i believe they have complete source for a text editor. today everyone uses the standard edit controls, so you'll have to go to dos code to find anything relevant.

the only thing i remember from turbovision is that they use a "window" to handle insertions and deletions. the window is positioned somewhere around the cursor position, and allows inserts/deletes of several characters without requiring moving the entire text around.

edit: well, speaking of notepad, it's just a thin wrapper around the "edit" control. you can probably make your own notepad (using the edit control) in a few hours. the real question is how that edit control is implemented, see above.

[edited by - niyaw on September 2, 2002 7:52:08 AM]

Share this post


Link to post
Share on other sites
I''d assume they store stuff in resizeable blocks, so inserting a character would only modify and move data around in that current block, instead of the entire edit control.

You might want to check the source to Scintilla, a free source code editing control.

Share this post


Link to post
Share on other sites