RyanRiffle / Poe

A word processor built with HTML, CSS, and JavaScript
GNU General Public License v3.0
21 stars 4 forks source link

[OS.js] Right alignment crashes application. #39

Closed RyanRiffle closed 9 years ago

RyanRiffle commented 9 years ago

To reproduce, open Poe in OS.js click align right button, then type [shift] + [any letter] Stack trace: TypeError: Cannot read property 'position' of undefined at Line.Poe.Line.Line.visiblyContains (http://localhost:8000/packages/default/Poe-OSjs/js/Line.js:40:23) at TextCursor.Poe.TextCursor.TextCursor.doWordWrap (http://localhost:8000/packages/default/Poe-OSjs/js/TextCursor.js:239:22) at TextCursor.Poe.TextCursor.TextCursor.handleInput (http://localhost:8000/packages/default/Poe-OSjs/js/TextCursor.js:547:12) at HTMLTextAreaElement. (http://localhost:8000/packages/default/Poe-OSjs/js/TextCursor.js:16:63) at HTMLTextAreaElement.jQuery.event.dispatch (http://localhost:8000/packages/default/Poe-OSjs/lib/jquery.js:4430:9) at HTMLTextAreaElement.elemData.handle (http://localhost:8000/packages/default/Poe-OSjs/lib/jquery.js:4116:28)

RyanRiffle commented 9 years ago

Poe.Line.visiblyContains is returning false every time a character is input when the alignment is right align. This causes an additional line to be added. It them throws an error because the new line has no children, because it then passes null to Poe.Line.visiblyContains.

visiblyContains could be changed to check the width of every child word, and if the total is greater than the line width, return true otherwise false. That however would add a whole lot of computations since word wrap is called every keypress which results in visiblyContains to be called.