I've been thinking of a project where it'd be nice to have a very
simple code editor. By "simple" I mean that I want to use the built-in
EditField rather than start from scratch (been there, done that, don't
have anywhere near enough time to do it again). I also don't need
anything fancy like syntax coloring or parenthesis matching.
You can already turn on a horizontal scrollbar, so we're 95% of the way
there. The one thing the EditField *doesn't* do is support tabs. This
is a real show-stopper for editing code, since tabs are (in most
languages) the standard way of indenting code blocks. You can set an
RB EditField to accept tabs, but the character it uses to draw them is
the same size as a regular space.
So, necessity being a mother and all that, I got inspired to put this
in the KeyDown event of an EditField:
static fakeTab As String = Encodings.UTF8.Chr( &h2003 )
if Key = Chr(9) then
me.selText = fakeTab
return true
end if
return false
Unicode &h2003 is the "Em Space" character. It's a whitespace
character that's significantly longer than your typical space
character. The code above intercepts any press of the Tab key and
inserts an Em Space instead.
The result is pretty encouraging â at the beginning of a line, at
least, this does a very convincing impression of a tab that's about 3-4
characters wide (depending on the font). It properly highlights when
you select it, gets deleted or cursored-over as a single character, etc.
To complete the illusion you'd want to intercept Copy and Paste and
convert regular tabs to/from em spaces, and likewise for
reading/writing files.
I haven't tried this on Windows or Linux yet. Anybody want to give it
a quick whirl and report back?
Finally, does anybody else think that simple tab stops of about 4 "m"'s
width would be a great addition to the EditField? We don't need the
EditField to turn into a word processor, but this one addition would
really open up a whole new set of applications for it (like editing
code!). Or, failing that, should the EditField at least draw the tab
character wider, as this hack makes it do?
Best,
- Joe
--
Joe Strout -- [EMAIL PROTECTED]
Verified Express, LLC "Making the Internet a Better Place"
http://www.verex.com/
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>