Click here to Skip to main content
15,901,505 members
Articles / Web Development / HTML

Typewriter.NET Text Editor

Rate me:
Please Sign up or sign in to vote.
3.69/5 (7 votes)
9 Nov 2018CPOL1 min read 11K   559   9   2
How to write your Notepad


I wanted to develop a text editor that didn't require too much effort for using and learning. The result is several simple principles:

  • Editor works without mouse (and without arrows in vi-mode)
  • No monotonic actions required due to multiple cursors:

    Image 1

    vi-mode, macroses

  • Allow cursor jumping in the direction of gaze (press space in vi-mode, press char at cursor, then showing chars)
  • Uses the simple concept of the current folder instead of the project
  • Easy searching how to do something by Ctrl+Shift+P. And using full-text searching inside help
  • External compiler or build script can be appended by only one line in config
  • Settings via text files changing or setting values from the command dialog (such parameters are written without the value attribute in the config), which allows not to search for them in the interface

Using the Code

Typewriter.NET is useful to develop itself. To build and run Typewriter.NET:

  • Open typewriter-net as current folder in editor (F4).
  • Press F5.
  • This shortcut runs command in config:
    <item name="f5Command" 
    value="!c:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe /verbosity:m 
    /p:Configuration=Release /target:tw"/>

    This line allows autocompletion:

    <item name="omnisharpSln" value="."/>

Creation Your Own Commands

You need to change Commander.cs - write your command in commands list:

public void Init(MainForm mainForm, Settings settings, TempSettings tempSettings)
    this.mainForm = mainForm;
    this.settings = settings;
    this.tempSettings = tempSettings;

    history = tempSettings.CommandHistory;
    commands.Add(new Command("help", "", "open/close tab with help text", DoHelp));
    commands.Add(new Command("replb", "[{…}]command", "open REPL bottom", DoReplBottom));

Explore enum command, that enters numbers at every cursor:

commands.Add(new Command("enum", "[n0] [step] [count]", "...", DoEnum));
commands.Add(new Command("enum0", "[n0] [step] [count]", "...", DoEnum0));
commands.Add(new Command("enumr", "[n0] [step] [count]", "...", DoEnumr));
private void DoEnum(string text)
    ProcessEnum(text, EnumGenerator.Mode.Number);

private void DoEnum0(string text)
    ProcessEnum(text, EnumGenerator.Mode.ZeroBeforeNumber);

private void DoEnumr(string text)
    ProcessEnum(text, EnumGenerator.Mode.Roman);

private void ProcessEnum(string text, EnumGenerator.Mode mode)
    EnumGenerator generator = new EnumGenerator
                  (text, lastBuffer.Controller.SelectionsCount, mode);

How to Append Menu Item

Common item you can append inside MainForm.cs:

private void BuildMenu()
    keyMap = new KeyMap();
    doNothingKeyMap = new KeyMap();

    doNothingKeyMap.AddItem(new KeyItem(Keys.Escape, null, KeyAction.Nothing));
    doNothingKeyMap.AddItem(new KeyItem(Keys.Escape | Keys.Shift, null, KeyAction.Nothing));
    doNothingKeyMap.AddItem(new KeyItem(Keys.Control | Keys.J, null, KeyAction.Nothing));
    doNothingKeyMap.AddItem(new KeyItem(Keys.Control | Keys.K, null, KeyAction.Nothing));

    keyMap.AddItem(new KeyItem(Keys.Control | Keys.N, null,
                               new KeyAction("&File\\New", DoNew, null, false)));
    keyMap.AddItem(new KeyItem(Keys.Control | Keys.O, null,
                               new KeyAction("&File\\Open", DoOpen, null, false)));
    keyMap.AddItem(new KeyItem(Keys.None, null, new KeyAction("&File\\-",
                               null, null, false)));
    keyMap.AddItem(new KeyItem(Keys.None, null,
    new KeyAction("&?\\Kate syntax highlighting help…", DoOpenSyntaxHelp, null, false)));
private bool DoOpenSyntaxHelp(Controller controller)
    OpenDocument(Path.Combine(AppPath.StartupDir, "syntax/syntax.html"));
    return true;

True command result stops shortcut reaction by other actions with equal shortcut keys.

Autocomplete Implementation

Make simple autocomplete for example:

  • Create your own autocomplete command:
    commands.Add(new Command("simple-autocomplete", "",
                             "simple autocomplete", DoSimpleAutocomplete));
    public void DoSimpleAutocomplete(string text)
        Buffer lastBuffer = mainForm.LastBuffer;
        if (lastBuffer == null)
            mainForm.Dialogs.ShowInfo("Error", "No buffer");
        Selection selection = lastBuffer.Controller.LastSelection;
        Place place = lastBuffer.Controller.Lines.PlaceOf(selection.anchor);
        string word = lastBuffer.Controller.GetLeftWord(place);
        List<Variant> variants = new List<Variant>();
        for (int i = 1; i <= 3; i++)
            Variant variant = new Variant();
            variant.CompletionText = "simple_" + i;
            variant.DisplayText = "simple_" + i;
        if (mainForm.LastFrame.AsFrame != null)
            mainForm.LastFrame.AsFrame.ShowAutocomplete(variants, word);
  • Setup shortuct for autocomplete inside text files in config:
    <item name="ctrlSpaceCommand:*.txt" value="simple-autocomplete"/>


  • 05.11.2018 First change


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionQuestion about the code history Pin
mccrim0112-Nov-18 8:22
professionalmccrim0112-Nov-18 8:22 
AnswerRe: Question about the code history Pin
Сергей Челноков13-Nov-18 5:29
Сергей Челноков13-Nov-18 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.