Another life-changing fantastic idea for quotes! (Bit silly, too.)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #30, on March 13th, 2011, 12:25 AM »
Quote
What about... If I cut a code tag that's located in a nested quote? (i.e. not directly inside the main quote.)
I'd argue it should replicate the end code bbc in before the cut, and open a new code bbc in the new quote. That way the tags are what they should be, and will be legally nested later.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #31, on March 13th, 2011, 12:45 AM »
It's a bit complex but... Well, I guess I can get a copy of the text between the last [quote] opened and the current cursor position, get a list of all opened and unclosed tags, and reopen them in order.
Still... It's going to make the code at least twice bigger. Meh.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #33, on March 13th, 2011, 07:32 PM »
It's quite complicated per se...
But I've made it. (Phew.)
This isn't optimized, but it's working at least.
This replaces the second half of the function... Obviously it's much longer. Can't do much about that... Feel free to optimize yourself, too.

Code: [Select]
// Build a list of opened tags...
var
selection = this.value.substr(0, selectionStart), lcs = selection.toLowerCase(),
lcsl = lcs.length, pos = 0, tag, bbcode, taglist = [], extag, log_tags = true,
protect_tags = ['code', 'php', 'html'];
while (true)
{
pos = lcs.indexOf('[', pos) + 1;
if (!pos)
break;
tag = selection.substring(pos, lcs.indexOf(']', pos + 1));
bbcode = tag.substr(tag.charAt(0) === '/' ? 1 : 0);

if (tag.charAt(0) === '/')
{
if (!log_tags && bbcode != taglist[taglist.length - 1].substr(0, bbcode.length))
continue;
do
{
extag = taglist.pop();
if (in_array(extag, protect_tags))
log_tags = true;
}
while (extag && bbcode != extag.substr(0, bbcode.length).toLowerCase());
}
else if (log_tags)
taglist.push(bbcode);
if (log_tags && in_array(bbcode, protect_tags))
log_tags = false;
}
for (var closers = [], j = 0, l = taglist.length; j < l; j++)
closers[] = '[/' + (taglist[j].indexOf(' ') > 0 ? taglist[j].substr(0, taglist[j].indexOf(' ')) : taglist[j]) + ']';
surroundText(closers.reverse().join('') + '\n', '\n\n[' + taglist.join('][') + ']', this);

return true;

NB: this uses the original quote params, rather than "continued".

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #34, on March 13th, 2011, 07:51 PM »
I just realised another issue with it, if you're wrapping tags - you'd have to pass a list of closed tags to the parsing function otherwise it would see the br tag and attempt to close it, no?

(As for me, for the first time in 2 years, I'm experimenting with a theme as opposed to UI tweaks :o)

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #36, on March 13th, 2011, 08:34 PM »Last edited on March 13th, 2011, 11:27 PM by Nao/Gilles
Here's the complete code, updated for self-closing tags... I've laid the tags out to make them easier to mod (oh... How I hate the word. But I can hardly do it differently. Unless you have an idea...)

Code: [Select]
// Split a quote if we press Enter inside it.
function splitQuote(oEvent)
{
// Did we just press Enter?
if (oEvent.which != 13)
return true;

// Where are we, already?
if ('selectionStart' in this)
var selectionStart = this.selectionStart;
else
{
var range = document.selection.createRange(), dul = range.duplicate();
dul.moveToElementText(this);
dul.setEndPoint('EndToEnd', range);
var selectionStart = dul.text.length - range.text.length;
}

// Build a list of opened tags...
var
selection = this.value.substr(0, selectionStart), lcs = selection.toLowerCase(),
lcsl = lcs.length, pos = 0, tag, bbcode, taglist = [], extag, log_tags = true,
protect_tags = [
'code',
'php',
'html',
],
closed_tags = [
'br',
'hr',
'more',
];
while (true)
{
pos = lcs.indexOf('[', pos) + 1;
if (!pos)
break;
tag = selection.substring(pos, lcs.indexOf(']', pos + 1));
bbcode = tag.substr(tag.charAt(0) === '/' ? 1 : 0);

if (tag.charAt(0) === '/')
{
if (!log_tags && bbcode != taglist[taglist.length - 1].substr(0, bbcode.length))
continue;
do
{
extag = taglist.pop();
if (in_array(extag, protect_tags))
log_tags = true;
}
while (extag && bbcode != extag.substr(0, bbcode.length).toLowerCase());
}
else if (log_tags && !in_array(bbcode, closed_tags))
taglist.push(bbcode);
if (log_tags && in_array(bbcode, protect_tags))
log_tags = false;
}
for (var closers = [], j = 0, l = taglist.length; j < l; j++)
closers.push('[/' + (taglist[j].indexOf(' ') > 0 ? taglist[j].substr(0, taglist[j].indexOf(' ')) : taglist[j]) + ']');
surroundText(closers.reverse().join('') + '\n', '\n\n[' + taglist.join('][') + ']', this);

return true;
};

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #37, on March 13th, 2011, 09:00 PM »
We'd actually have to pass the list of closed tags to the JS because although the list is only three tags now, it might not be in future.

As for the theme, just playing with some different header ideas and seeing how well the sidebar worked on the right.

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #38, on March 13th, 2011, 09:32 PM »
Quote from Arantor on March 13th, 2011, 09:00 PM
We'd actually have to pass the list of closed tags to the JS because although the list is only three tags now, it might not be in future.
I know, I know... But if we pass it, we'll also have to pass the list of unparse_content tags (a matter of logic)...
BTW, I forgot to add nobbc to the list. Done locally.

Anyway, I figured you can do it if you want, now that the stuff is committed ;)

Also, what do you think of the result...? I haven't added anything to make it disablable (is that a real word?), because let's just say... I'm quite happy with it. Of course it's going to crash/behave badly in plenty of situations... I'm sure a [quo[b][/b]te] wouldn't behave well... Or splitting a quote right inside a [url=something_very_long] tag...
Quote
As for the theme, just playing with some different header ideas and seeing how well the sidebar worked on the right.
It's fun innit? ;)
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #39, on March 13th, 2011, 11:27 PM »
Okay, I've generated the list dynamically. (Query-free, since parse_bbc(false) generates the list from the current bbc cache.)

You might wanna test the entire thing on complex messages if you have some time... Notably, mixing quotes with code tags is okay but if you do several in a row, Wedge seems to give up at some point... It ends up emptying the taglist array, indicating that it 'missed' the matching tag when going through the pop() loop.
Bed time for me, so if you can find the 'culprit'... Please fix it for me :)
Posted: March 13th, 2011, 11:21 PM

AFAICS, the bug (also?) happens when we just press the Enter key in an area that is NOT within a quote... So, obviously, Wedge will return an empty array, uh. Dull! :lol: But I'm pretty sure I still managed to trigger the bug within a code tag.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,078

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #42, on March 17th, 2011, 06:10 PM »
I've had a play with it, and it's certainly interesting, just gotta get used to it, you know? I need to be sure in my own mind when it's acting up and when it's behaving as expected.

I also get the distinct impression an option to disable it (either forum wide or per user) wouldn't be a bad idea.

Nao

  • Dadman with a boy
  • Posts: 16,078
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #43, on March 17th, 2011, 06:30 PM »
I don't think forum wide would be very logical. This is a helper and it isn't as buggy as, say, the Wysiwyg engine...
A per-user setting, yeah, I thought about that but am too lazy ;) Spent too much time and that feature and it didn't even end up the way I wanted... (I wanted the > stuff, and in the end I did something else :P) (I still have the code for ">", btw... Maybe I'll commit it in the future, in the wip folder.)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Another life-changing fantastic idea for quotes! (Bit silly, too.)
« Reply #44, on March 18th, 2011, 12:16 AM »
Quote
I don't think forum wide would be very logical.
True enough. I just get the impression that some people are going to freak out though.
Quote
A per-user setting, yeah, I thought about that but am too lazy
We really need to overhaul that actually. The way it's implemented feels wrong to me. If you ever looked at it, you'll understand why it feels wrong, I think.