diff --git a/root/includes/editor.php b/root/includes/editor.php index 3fd6798..42be49a 100644 --- a/root/includes/editor.php +++ b/root/includes/editor.php @@ -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') { @@ -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; diff --git a/root/includes/mod_parser.php b/root/includes/mod_parser.php index 9dc48e9..8d4870a 100644 --- a/root/includes/mod_parser.php +++ b/root/includes/mod_parser.php @@ -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;