In-browser code editing Marijn Haverbeke (Interactive slides at - - PowerPoint PPT Presentation

in browser code editing
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

In-browser code editing

Marijn Haverbeke

(Interactive slides at http://marijnhaverbeke.nl/talks/goto2012)

slide-2
SLIDE 2

a 3-part talk:

state of the art ❇ inspirational demo ❇ implementation war stories ❇

slide-3
SLIDE 3

textarea schmextarea

slide-4
SLIDE 4

who's who

ACE ❇ CodeMirror ❇ Orion ❇

slide-5
SLIDE 5

ACE ≈ furniture CodeMirror ≈ timber

slide-6
SLIDE 6

trust me I am biased

slide-7
SLIDE 7

demotime

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

but how does it

work?

slide-11
SLIDE 11

the cursor is a lie

slide-12
SLIDE 12

those scrollbars?

not real

either

slide-13
SLIDE 13

scrolling model

slide-14
SLIDE 14

who's afraid of

huge files?

slide-15
SLIDE 15

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

slide-16
SLIDE 16
slide-17
SLIDE 17

startState: function() → state token: function(stream, state) → string indentation: function(state, string) → integer

slide-18
SLIDE 18

mode state updates

slide-19
SLIDE 19

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

slide-20
SLIDE 20

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

the

future

slide-23
SLIDE 23

aside:

Orion's

approach

slide-24
SLIDE 24

that's all, folks

http://codemirror.net marijnjh