bevacqua / woofmark

:dog2: Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor
https://bevacqua.github.io/woofmark
MIT License
1.62k stars 74 forks source link

History code appearing upon refreshing page? #8

Open danvim opened 9 years ago

danvim commented 9 years ago

I have been testing the software and I think I've found a bug?

I'm using Firefox Nightly 41,

Problem: Texts unexpected appended to editor upon refresh

Expected Text: space

Resulted Text: First time. spaceWoofmarkSelectionOpenMarkergbdhcWoofmarkSelectionCloseMarkergbdhc Second time. spaceWoofmarkSelectionOpenMarkerecaacbhWoofmarkSelectionCloseMarkerecaacbh

Procedures: Input space or any text into WYSIWYG mode, refresh page.

Analysis: The string "WoofmarkSelectionOpenMarker" + code string + "WoofmarkSelectionCloseMarker" + repeated code string is appended to text upon every refresh on WYSIWYG mode with some text input.

bevacqua commented 9 years ago

Weird. These are used to persist the selection across input modes, but shouldn't stay in the editor. Can you invetigate this issue yourself? Relevant code is here: https://github.com/bevacqua/woofmark/blob/master/src/rememberSelection.js#L24

danvim commented 9 years ago

https://github.com/bevacqua/woofmark/blob/master/dist/woofmark.js#L3488-3490

capture

Somehow, your script failed to replace the rmarkers.

danvim commented 9 years ago

capture

You script failed to find the rmarker because the page has been _refreshed_ and a new code is generated.

You should probably create an open tag and an end tag wrapping the code, so as to use regex to find it even if the code is irrelevant, e.g.

WoofmarkSelectionOpenMarker{{abcdefgh}} WoofmarkSelectionCloseMarker{{abcdefgh}}

https://github.com/bevacqua/woofmark/blob/master/dist/woofmark.js#L3456

bevacqua commented 9 years ago

Could you create a PR with the fix?

danvim commented 9 years ago

Replacing https://github.com/bevacqua/woofmark/blob/master/dist/woofmark.js#L3457-3459

with

var code = Math.random().toString(18).substr(2).replace(/\d+/g, '');
var open = 'WoofmarkSelectionOpenMarker{{' + code + '}}';
var close = 'WoofmarkSelectionCloseMarker{{' + code + '}}';
//var rmarkers = new RegExp(open + '|' + close, 'g');
var rmarkers = new RegExp('WoofmarkSelectionOpenMarker{{.+}}|WoofmarkSelectionCloseMarker{{.+}}', 'g');

solves the problem with refreshing the page in WYSIWYG mode, but I'm sure the code is there for a reason. If the regex matches any code, would it break the program?

Sorry, but I'm really no expert at JavaScript

bevacqua commented 8 years ago

I can't reproduce this either. Please help me reproduce

danvim commented 8 years ago

Similar to the other issue, I'm using Nightly, but Firefox should do.

Steps:

  1. Use http://bevacqua.github.io/woofmark/
  2. Use "wysiwyg" mode.
  3. Delete everything and paste in space.
  4. Click the refresh button on the right of the address bar.
  5. You should notice the editor now contains WoofmarkSelectionOpenMarkerefcdagfWoofmarkSelectionCloseMarkerefcdagfspace
danvim commented 8 years ago

@bevacqua I discovered that, on Firefox, it tried to keep the content, but on Chrome, the editor resets. Perhaps you haven't considered Firefox for testing?

bevacqua commented 8 years ago

I haven't done thorough testing on Firefox. Can you work out a fix for this issue?

danvim commented 8 years ago

@bevacqua If you look up, I've tried a fix for the problem, accounting that Firefox tries to save what was inputted. I wrapped the code with brackets so they can be detected and removed.

Sorry, but I'm really no expert in JavaScript, my "fixes" might just be silly codings :(

blindwaves commented 8 years ago

The input autocompletion is probably the culprit here. You can try disabling the autocompletion as per the linked article if you do not want the browser to "remember" the modified content on refresh.