Giter VIP home page Giter VIP logo

hilarious-text-editor's Introduction

Overview

hilarious-text-editor lets you edit text files in a web browser. It autosaves every few seconds. You need to install Python 3.4 or higher before you can run it.

./hilarious.py --help

./hilarious.py path-to-file-or-directory-to-edit-things-in

Don't choose a directory with too many hundreds of text files in it. (See Limitations below.)

Follow the directions it shows on stdout for what link to open in your web browser. Probably http://localhost:3419/ and probably you'll then have a secret authentication token in your clipboard you can paste in to start editing. (See Security below for why there's a secret.)

I wrote this because Dragon NaturallySpeaking is pretty effective at controlling HTML <textarea>s in IE 11. My friends wanted a text editor for coding with Dragon that has fewer misfeatures for that purpose than DragonPad or Microsoft Word. If you have another use for this editor, I'd love to hear about it! Or even if you are using it for this purpose!

The editor could integrate something like http://ace.c9.io/ as an editor, but it probably won't because Dragon gets a little confused by the fancy things those editors do (in ace editor, for example, most of the text in the document is not in the <textarea> element at any given time, but is instead in other elements. Presumably so they can syntax hilight it and/or be more asymptotically efficient at editing. With the CodeMirror editor โ€” used for example by twine2 โ€” I am even less sure what exactly it's doing in the DOM.

Limitations

It doesn't work well when there are too many files in the directory.

It doesn't even let you edit sufficiently large text files, because it would be too slow in the browser and/or autosaving.

Security

Since you're (probably) a coder, you'll be editing scripts that you'll then (probably) be running in your user account, so you don't want other people to sneak in and edit your files over HTTP. If they could, they could then (probably) run their code as your user account.

Preventing this is implemented in parts:

  • Transport security: connecting to localhost or over HTTPS. (HTTPS not implemented yet; you can't use it remotely at all yet unless you hack the source code to do that insecurely.)

  • CSRF protection: all server requests involving private data are XHR2 Ajax POST requests with custom HTTP header fields that the server checks, in addition to checking Origin or Referer. This means they can't be posted to cross-domain.

  • What if someone else connects to the server:

    • When serving on localhost, only localhost users can connect at all
    • Unless you disable the random token, sending a correct token is required for all requests that involve private data. The random token is only sent to the clipboard and/or stdout, so other Unix/Windows users on the same system won't easily be able to get a copy of it.
  • The server not having bugs like memory corruption: it's Python with none of my code using the FFI, so that helps.

Anyone who can connect to the server can probably DOS it, but that's less of an issue. Let me know if you want me to do something about this. (A best solution would likely include putting it behind a reverse proxy such as nginx... so not suitable for all uses.)

hilarious-text-editor's People

Contributors

elidupree avatar idupree avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

elidupree

hilarious-text-editor's Issues

Needs Readme :)

I managed to launch it, but how do I do all the other things?

A Readme could tell me :)

Page Down in textarea behaves oddly

It scrolls all the way down, rather than just one page down, at least with Firefox Linux keyboard PageDown and IE Dragon pagedown. Mirror problem with PageUp.

fix undo with switching files

Apparently browsers keep programmatic changes to a textarea in the textarea's undo history. At least some of them. Firefox does; Chromium doesn't. (Testing on Linux - there could well be OS differences too.)

There's no API to change a textarea's undo history. (Unless my Google-fu failed me;. I found a 2012 draft of an undo api but no evidence it made it into any spec or implementation.) However you can possibly create another textarea and delete the old textarea to clear the undo history (or at any rate, that would likely prevent the undo history from doing catastrophically wrong things). On Firefox, programmatically changing the textarea could be used to initialize an undo history, but that doesn't seem cross-browser enough to bother. (Particularly since Firefox is not a great browser to use with this editor, due to a reflow issue with Firefox, and since Dragon seems to work best with IE. It's possible IE also behaves this way, in which case it might be worth doing.) In any case, I don't want things to be more broken than they have to be on Firefox, so that means creating each new textarea with its initial contents already in it so that you can't undo yourself to an empty file by accident and delete all your work. For example, I can do this by something along the lines of createElement('div').innerHTML = '<textarea>'+escape(textareaContents)+'</textarea>'.

The undo stack is per-textarea in Firefox, but per the entire page in Chromium. In Chromium, when you undo, it focuses the textarea that you are undoing in, and makes the change. Except that if that textarea is display:none at the time, then it makes no change instead. This means you can generate infinite text by

  1. type something in a textarea
  2. make the textarea display:none
  3. undo (Ctrl-Z)
  4. make the textarea display:block
  5. redo (Ctrl-Shift-Z)
  6. go to step 2 (unless bored)
  7. profit???

This issue also means the Firefox textarea-reflowing workaround maybe should be scrapped, because the workaround messes up the undo history in Firefox. Instead, make the textarea longer-than-necessary just in case, and warn the user that the line numbers may be wrong sometimes (particularly if the user has verrrry long lines, but even a single wrapped line is occasionally enough to cause this problem depending exactly where the spaces are in the line and depending on luck.)

I've found no way to detect the problem programmatically. Firefox is too confused to adjust scrollHeight to be the abnormally large height that it needs to be when this happens, and it doesn't happen in the same way in the #testline textarea. TODO: create textcase and submit to moz bugzilla; searching https://www.google.com/search?q=textarea+reflow+scrollHeight+site%3Abugzilla.mozilla.org didn't find any that appeared relevant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.