In-browser code editing
Marijn Haverbeke
(Interactive slides at http://marijnhaverbeke.nl/talks/goto2012)
In-browser code editing Marijn Haverbeke (Interactive slides at - - PowerPoint PPT Presentation
In-browser code editing Marijn Haverbeke (Interactive slides at http://marijnhaverbeke.nl/talks/goto2012) a 3-part talk: state of the art inspirational demo implementation war stories textarea schmextarea who's who ACE
In-browser code editing
Marijn Haverbeke
(Interactive slides at http://marijnhaverbeke.nl/talks/goto2012)
a 3-part talk:
state of the art ❇ inspirational demo ❇ implementation war stories ❇
who's who
ACE ❇ CodeMirror ❇ Orion ❇
ACE ≈ furniture CodeMirror ≈ timber
trust me I am biased
cm.on("change", runLinter)
!! Missing semicolon.var curSlide, slides; // Slide/hashmark management CodeMirror.on(window, "load", function() { slides = document.body.getElementsByTagName("slide"); runTimer() changeSlide(document.location.hash ? Number(document.location.hash.slice(1)) : CodeMirror.on(window, "scroll", function() { if (atSlide(curSlide)) return; for (var i = 0; i < slides.length; ++i) if (atSlide(i)) { var atEnd = document.body.scrollTop > document.body.scrollHeight - document.documentElement.clientHeight - 10; changeSlide(i, !atEnd); return; } }); CodeMirror.on(window, "hashchange", function() { 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21
a taste of ACE
var curSlide, slides; // Slide/hashmark management CodeMirror.on(window, "load", function() { slides = document.body.getElementsByTagName("slide"); runTimer(); changeSlide(document.location.hash ? Number(document.location.hash.slice(1)) : CodeMirror.on(window, "scroll", function() { if (atSlide(curSlide)) return; for (var i = 0; i < slides.length; ++i) if (atSlide(i)) { var atEnd = document.body.scrollTop > document.body.scrollHeight - document.documentElement.clientHeight - 10; changeSlide(i, !atEnd); return; } }); CodeMirror.on(window, "hashchange", function() { var n = document.location.hash ? Number(document.location.hash.slice(1)) : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
but how does it
the cursor is a lie
those scrollbars?
either
scrolling model
who's afraid of
document b-tree
var curSlide, slides; // Slide/hashmark management CodeMirror.on(window, "load", function() { slides = document.body.getElementsByTagName("slide "); runTimer(); changeSlide(document.location.hash ? Number(document.location.hash.slice(1)) : 0); CodeMirror.on(window, "scroll", function() { if (atSlide(curSlide)) return; for (var i = 0; i < slides.length; ++i) if (atSlide(i)) { var atEnd = document.body.scrollTop > document.body.scrollHeight - document.documentElement.clientHeight - 10; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
startState: function() → state token: function(stream, state) → string indentation: function(state, string) → integer
mode state updates
highlighting tag mismatch
<document> <section> <item name="item0">01100111010101000111</item> <item name="item1" type="2">11010000112001</item> </secion> </document> 1 2 3 4 5 6 7
spotting local variables
(function(){ function count(array, elt) { var found = 0; for (var i = 0; i < array.length; ++i) if (array[i] === elt) ++found; console.log(array, found); return fund; } })(); 1 2 3 4 5 6 7 8 9 10
modes compose easily
<!doctype html> <head> <meta charset="utf-8"> <title>Test HTML</title> <style> p#main { color: #90440a; } </style> </head> <p id="main">I am HTML</p> <script> window.onload = function() { alert("Hi, I am JavaScript"); }; </script> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
the
aside:
approach
that's all, folks
http://codemirror.net marijnjh