diff --git a/features/rectangular-region.feature b/features/rectangular-region.feature new file mode 100644 index 0000000..b1b45bc --- /dev/null +++ b/features/rectangular-region.feature @@ -0,0 +1,73 @@ +Feature: Rectangular region + + Scenario: Works like regular region when on one line + When I insert "some text" + And I press "H-SPC" + And I press "M-b" + Then the region should be "text" + And rectangular-region-mode should be on + + Scenario: Works like regular region when on one line, insert + Given I turn on delete-selection-mode + When I insert "some text" + And I press "H-SPC" + And I press "M-b" + And I type "replacement" + Then I should see "some replacement" + And rectangular-region-mode should be off + + Scenario: Works like regular region when on one line, copy 1 + Given I turn on delete-selection-mode + When I insert "some text" + And I press "H-SPC" + And I press "M-b" + And I press "M-w" + Then rectangular-region-mode should be off + + Scenario: Works like regular region when on one line, copy 2 + Given I turn on delete-selection-mode + When I insert "some text" + And I press "H-SPC" + And I press "M-b" + And I press "M-w" + And I press "C-y" + Then I should see "some texttext" + + Scenario: Changing multiple lines + Given I turn on delete-selection-mode + When I insert: + """ + This is some text + This is more text + """ + And I go to point "6" + And I press "H-SPC" + And I press "M-f" + And I press "C-n" + And I type "was" + Then I should see: + """ + This was some text + This was more text + """ + And I should have 2 cursors + + Scenario: Changing multiple lines with gaps + Given I turn on delete-selection-mode + When I insert: + """ + This is some text + + This is more text + """ + And I go to point "6" + And I press "H-SPC" + And I go to the end of the word "more" + And I type "was" + Then I should see: + """ + This was text + + This was text + """ + And I should have 2 cursors diff --git a/features/step-definitions/multiple-cursors-steps.el b/features/step-definitions/multiple-cursors-steps.el index 990f19a..3ecc367 100644 --- a/features/step-definitions/multiple-cursors-steps.el +++ b/features/step-definitions/multiple-cursors-steps.el @@ -15,6 +15,16 @@ (assert (eq 1 (mc/num-cursors)) nil "Expected to have one cursor, but there are still fake cursor overlays."))) +(Then "^rectangular-region-mode should be off$" + (lambda () + (assert (not rectangular-region-mode) nil + "Expected rectangular-region-mode mode to be off, but wasn't."))) + +(Then "^rectangular-region-mode should be on$" + (lambda () + (assert (rectangular-region-mode) nil + "Expected rectangular-region-mode mode to be on, but wasn't."))) + (When "^I press \"\\(.+\\)\"$" (lambda (keybinding) (let ((macro (edmacro-parse-keys keybinding))) @@ -57,3 +67,18 @@ (lexical-let ((ins ins)) (defun mc-test-temp-command-2 () (interactive) (insert ins)) (global-set-key (kbd "C-!") 'mc-test-temp-command-2)))) + +(When "^I go to character \"\\(.+\\)\"$" + (lambda (char) + (goto-char (point-min)) + (let ((search (re-search-forward (format "%s" char) nil t)) + (message "Can not go to character '%s' since it does not exist in the current buffer: %s")) + (assert search nil message char (espuds-buffer-contents))))) + +(When "^I go to the \\(front\\|end\\) of the word \"\\(.+\\)\"$" + (lambda (pos word) + (goto-char (point-min)) + (let ((search (re-search-forward (format "%s" word) nil t)) + (message "Can not go to character '%s' since it does not exist in the current buffer: %s")) + (assert search nil message word (espuds-buffer-contents)) + (if (string-equal "front" pos) (backward-word))))) diff --git a/features/support/env.el b/features/support/env.el index 8a61240..d7a4748 100644 --- a/features/support/env.el +++ b/features/support/env.el @@ -17,8 +17,10 @@ (Before (multiple-cursors-mode 0) + (rectangular-region-mode 0) (mm/clear-all) (global-set-key (kbd "C->") 'mark-next-like-this) + (global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor) (switch-to-buffer (get-buffer-create "*multiple-cursors*")) (erase-buffer) diff --git a/rectangular-region-mode.el b/rectangular-region-mode.el index cb84e04..6493003 100644 --- a/rectangular-region-mode.el +++ b/rectangular-region-mode.el @@ -61,6 +61,10 @@ (when rectangular-region-mode (rrm/switch-to-multiple-cursors))) +(defadvice kill-ring-save (before switch-from-rrm-to-mc activate) + (when rectangular-region-mode + (rrm/switch-to-multiple-cursors))) + (define-minor-mode rectangular-region-mode "A mode for creating a rectangular region to edit" nil " rr" rectangular-region-mode-map diff --git a/run-tests.watchr b/run-tests.watchr index c2f39c2..3810cb2 100644 --- a/run-tests.watchr +++ b/run-tests.watchr @@ -7,13 +7,13 @@ end def run_all_tests system('clear') - result = run "./util/ecukes/ecukes" + result = run "./util/ecukes/ecukes --graphical" puts result end def run_test(file) system('clear') - result = run "./util/ecukes/ecukes #{file}" + result = run "./util/ecukes/ecukes --graphical #{file}" puts result end