Skip to content

Commit

Permalink
[ticket/62558] Support reversal of multi inline-edits on same find
Browse files Browse the repository at this point in the history
With this change, the reverse is now built just like the normal
(install) action - per the process_edits method of the acp_mods
class. This fixes the bug where AM failed to reverse all but
the last one of the multiple in-line edit's on the same line/find.
Also did some minor optimizations of editor->build_uninstall.
  • Loading branch information
jasmineaura committed Dec 17, 2010
1 parent f21d819 commit 2e2860e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
48 changes: 32 additions & 16 deletions root/includes/editor.php
Expand Up @@ -679,21 +679,14 @@ function build_uninstall($find, $inline_find, $action_type, $action)
(($this->last_action[2] == 'AFTER' && $this->curr_action[2] == 'BEFORE')
|| ($this->last_action[2] == 'BEFORE' && $this->curr_action[2] == 'AFTER')))
{
$last_action_index = sizeof($this->mod_actions[$this->open_filename]) - 1;
unset($this->mod_actions[$this->open_filename][$last_action_index]);

// Re-index the array to start at zero and go sequentially
$this->mod_actions[$this->open_filename] = array_merge($this->mod_actions[$this->open_filename]);
array_pop($this->mod_actions[$this->open_filename]);

$action_type = 'REPLACE';

// Remove the add from the find -- this is an effect of the way the
// add method works, putting the new lines in the same array element
// as the find
if (!empty($this->last_action))
{
$find = str_replace(trim($this->last_action[1]), '', $find);
}
$find = str_replace(trim($this->last_action[1]), '', $find);

if ($this->last_action[2] == 'AFTER')
{
Expand All @@ -718,15 +711,38 @@ function build_uninstall($find, $inline_find, $action_type, $action)
}
else
{
$this->mod_actions[$this->open_filename][] = array(
$find => array(
'in-line-edit' => array(
$inline_find => array(
$action_type => array($action),
// Do we have preceding in-line-edit(s) on the same complete find or line?
if (!empty($this->last_action) && $this->last_action[0] == $this->curr_action[0])
{
$prev_inline_edits = array_pop($this->mod_actions[$this->open_filename]);
$prev_find = key($prev_inline_edits);

// Add our current in-line-edit
$prev_inline_edits[$prev_find]['in-line-edit'][] = array(
$inline_find => array(
$action_type => array($action),
),
);

// Add the new set of in-line-edit's to our MOD Actions array, w/ the updated $find
$this->mod_actions[$this->open_filename][] = array(
$find => $prev_inline_edits[$prev_find]
);
}
else
{
$this->mod_actions[$this->open_filename][] = array(
$find => array(
'in-line-edit' => array(
array(
$inline_find => array(
$action_type => array($action),
),
),
),
),
),
);
);
}
}

$this->last_action = $this->curr_action;
Expand Down
46 changes: 24 additions & 22 deletions root/includes/mod_parser.php
Expand Up @@ -188,33 +188,35 @@ function reverse_edits($actions)
break;

case 'IN-LINE-EDIT':
$action_id = 0;
// build the reverse just like the normal action
foreach ($command as $inline_find => $inline_action_ary)
foreach ($command as $action_id => $inline_edit)
{
foreach ($inline_action_ary as $inline_action => $inline_command)
foreach ($inline_edit as $inline_find => $inline_action_ary)
{
$inline_command = $inline_command[0];

switch (strtoupper($inline_action))
foreach ($inline_action_ary as $inline_action => $inline_command)
{
case 'IN-LINE-AFTER-ADD':
case 'IN-LINE-BEFORE-ADD':
// Replace with a blank string
$reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command]['in-line-replace'][] = '';
break;

case 'IN-LINE-REPLACE':
// replace with the inline find
$reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command][$inline_action][] = $inline_find;
break;

default:
// For the moment, we do nothing. What about increment?
break;
$inline_command = $inline_command[0];

switch (strtoupper($inline_action))
{
case 'IN-LINE-AFTER-ADD':
case 'IN-LINE-BEFORE-ADD':
// Replace with a blank string
$reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command]['in-line-replace'][] = '';
break;

case 'IN-LINE-REPLACE':
// replace with the inline find
$reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command][$inline_action][] = $inline_find;
break;

default:
// For the moment, we do nothing. What about increment?
break;
}

$action_id++;
}

$action_id++;
}
}
break;
Expand Down

0 comments on commit 2e2860e

Please sign in to comment.