Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Text Editor

Author
Message
Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 15th May 2012 19:11 Edited at: 17th May 2012 18:44
Hi,

due to this funny idea I recently had about writing yet another IDE for DBP (somewhat inspired by Light Table and being written directly in DBPro), I sat down yesterday and started writing a small text-Editor.
It does not use any plugins, so all the functionality is directly in the code. It supports usual features such as selecting stuff either via keyboard-input or using the mouse, a cursor, a potentially unlimited number of lines and all that.

Certain things, such as jumping over words using CTRL, a vertical bar showing the line numbers, scrolling, syntax highlighting and many more are not implemented yet, but this text editor already is a solid basis to rudimentary text editing. I tried to make it behave the same way most text editors do, but it is certainly possible that there are still some differences. Feel free to play around with it and inform me about anything that seems wrong.


Here's the code:



Note that the code is not that great, especially since I made use of the "gl_input"-library I wrote some time ago, although just very few functions of it are used, so most of this library is either completely unused or redundant.
Anyway, for now it works quite well, maybe I'm going to improve the code later, in case I'm actually going to use it for a project.

A screenshot of the editor:




In case you test it, please tell me your FPS-rate. I'm using the inbuilt text-commands (although they are easy to exchange since everything text-related is in a couple of small functions beginning at line 656), so it might be slow when there's a lot of text on the screen. Especially if I'm going to use syntax highlighting, since it will increase the amount of text-function-calls dramatically.

Anyway - thanks in advance for feedback in any shape or form. You may of course use and alter this code if you wish.

Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th May 2012 03:06
Nice, I get about 230fps on my laptop If you need any help with the syntax highlighting, I have some experience of that from writing the editor for TopGUI.

[b]
Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 17th May 2012 18:43
Updated Version: I added a bit of documentation, fixed a few bugs, added Cut/Copy/Paste-functions and drawing of line numbers. Automatic as well as manual scrolling will be added next.
Afterwards syntax highlighting and rightclick-menu, and then the most important requirements for a code editor are met, I think.

Updated Code:


Thank you Diggsey, and about the Syntax highlighting: My plan is to store information about the highlighting in an array for each line, so the whole text will not be stored as single string per line, but as a bunch of small strings, each with individual highlight-state and information about where it begins. Everytime a line is changed, the syntax information is recalculated, so it should be pretty efficient and relatively easy to implement. Does that sound like a good idea to you, or is there an easier way to tackle the problem?

Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 18th May 2012 15:43 Edited at: 18th May 2012 15:44
That seems like a reasonable way to solve it. The only problem I see is that there is no good way to store that kind of data-structure in DBPro.

The way I did in top-gui was just to store the syntax state of the start of each line, and each time a line is rendered, reparse that one line. If the syntax state is ever different at the end of a line from the start of the next one it know it needs to reparse that one as well. Simple, but it seemed to work quite well!

[b]
Sergey K
20
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 19th May 2012 13:09
wow very impressive.. i never imagined that some1 would actually do something like that in dbp

its like a Memo component for most of the programming languanges..

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Jun 2012 17:56
We had a text editor challenge some years ago in both DBP and DBC:

http://dbcodecorner.com/index.php?page=view&challenge=Text%20Editor

Unfortunately, due to a small oversight in coding my website, I can't pull up the DBP version of the contest.

"You're not going crazy. You're going sane in a crazy world!" ~Tick

Login to post a reply

Server time is: 2024-04-19 12:35:54
Your offset time is: 2024-04-19 12:35:54