From 130d0a168d15a67da7e85b0858c7e5b792bb253b Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Mon, 17 Sep 2012 23:33:22 +0200 Subject: [PATCH] Move check for indent corrections to OakTextView This makes it easier to introduce a UI setting for the option. --- Frameworks/OakTextView/src/OakTextView.h | 1 + Frameworks/OakTextView/src/OakTextView.mm | 13 +++++++++---- Frameworks/editor/src/editor.cc | 12 ++++++------ Frameworks/editor/src/editor.h | 4 ++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Frameworks/OakTextView/src/OakTextView.h b/Frameworks/OakTextView/src/OakTextView.h index b03a641f..face563a 100644 --- a/Frameworks/OakTextView/src/OakTextView.h +++ b/Frameworks/OakTextView/src/OakTextView.h @@ -99,6 +99,7 @@ PUBLIC @interface OakTextView : OakView @property (nonatomic, assign) BOOL showInvisibles; @property (nonatomic, assign) BOOL softWrap; @property (nonatomic, assign) BOOL softTabs; +@property (nonatomic, readonly) BOOL continuousIndentCorrections; @property (nonatomic, readonly) BOOL hasMultiLineSelection; @property (nonatomic, readonly) BOOL hasSelection; diff --git a/Frameworks/OakTextView/src/OakTextView.mm b/Frameworks/OakTextView/src/OakTextView.mm index 7d8881d6..94287745 100644 --- a/Frameworks/OakTextView/src/OakTextView.mm +++ b/Frameworks/OakTextView/src/OakTextView.mm @@ -1104,7 +1104,7 @@ static void update_menu_key_equivalents (NSMenu* menu, action_to_key_t const& ac if(event != OakChoiceMenuKeyCancel) { - editor->perform(ng::kInsertTab); + editor->perform(ng::kInsertTab, layout.get(), [self continuousIndentCorrections]); choiceVector.clear(); } } @@ -1164,7 +1164,7 @@ static void update_menu_key_equivalents (NSMenu* menu, action_to_key_t const& ac } [self recordSelector:_cmd withArgument:[aString copy]]; - editor->insert_with_pairing([aString UTF8String]); + editor->insert_with_pairing([aString UTF8String], [self continuousIndentCorrections]); } - (IBAction)toggleCurrentFolding:(id)sender @@ -1619,7 +1619,7 @@ static void update_menu_key_equivalents (NSMenu* menu, action_to_key_t const& ac if(![self expandTabTrigger:sender]) { [self recordSelector:_cmd withArgument:nil]; - editor->perform(ng::kInsertTab); + editor->perform(ng::kInsertTab, layout.get(), [self continuousIndentCorrections]); } } @@ -1718,6 +1718,11 @@ static void update_menu_key_equivalents (NSMenu* menu, action_to_key_t const& ac - (BOOL)showInvisibles { return showInvisibles; } - (BOOL)softWrap { return layout && layout->wrapping(); } +- (BOOL)continuousIndentCorrections +{ + return !plist::is_true(bundles::value_for_setting("disableIndentCorrections", editor->scope())); +} + - (void)setTheme:(theme_ptr const&)newTheme { theme = newTheme; @@ -2545,7 +2550,7 @@ static scope::context_t add_modifiers_to_scope (scope::context_t scope, NSUInteg { AUTO_REFRESH; [self recordSelector:aSelector withArgument:nil]; - editor->perform(anAction, layout.get()); + editor->perform(anAction, layout.get(), [self continuousIndentCorrections]); } #define ACTION(NAME) (void)NAME:(id)sender { [self handleAction:ng::to_action(#NAME ":") forSelector:@selector(NAME:)]; } diff --git a/Frameworks/editor/src/editor.cc b/Frameworks/editor/src/editor.cc index 3ee34b3c..8b937ff3 100644 --- a/Frameworks/editor/src/editor.cc +++ b/Frameworks/editor/src/editor.cc @@ -539,9 +539,9 @@ namespace ng struct indent_helper_t : ng::callback_t { - indent_helper_t (editor_t& editor, buffer_t& buffer) : _disabled(false), _editor(editor), _buffer(buffer) + indent_helper_t (editor_t& editor, buffer_t& buffer, bool indentCorrections) : _disabled(!indentCorrections), _editor(editor), _buffer(buffer) { - _disabled = editor._selections.size() != 1 || editor._selections.last().columnar || plist::is_true(bundles::value_for_setting("disableIndentCorrections", editor.scope())); + _disabled = _disabled || editor._selections.size() != 1 || editor._selections.last().columnar; if(_disabled) return; @@ -627,7 +627,7 @@ namespace ng return NULL_STR; } - void editor_t::insert_with_pairing (std::string const& str) + void editor_t::insert_with_pairing (std::string const& str, bool indentCorrections) { if(!has_selection()) { @@ -640,7 +640,7 @@ namespace ng } } - indent_helper_t indent_helper(*this, _buffer); + indent_helper_t indent_helper(*this, _buffer, indentCorrections); std::string const autoInsert = find_paired(str, scope()); if(autoInsert != NULL_STR && has_selection()) { @@ -693,7 +693,7 @@ namespace ng _selections = this->snippet(from, to, str, variables); } - void editor_t::perform (action_t action, layout_t const* layout) + void editor_t::perform (action_t action, layout_t const* layout, bool indentCorrections) { static std::string const kSingleMarkType = "•"; preserve_selection_helper_t selectionHelper(_buffer, _selections); @@ -884,7 +884,7 @@ namespace ng case kDeleteSelection: { - indent_helper_t indent_helper(*this, _buffer); + indent_helper_t indent_helper(*this, _buffer, indentCorrections); _selections = apply(_buffer, _selections, _snippets, &transform::null); } break; diff --git a/Frameworks/editor/src/editor.h b/Frameworks/editor/src/editor.h index 10c36625..93c6bd73 100644 --- a/Frameworks/editor/src/editor.h +++ b/Frameworks/editor/src/editor.h @@ -152,12 +152,12 @@ namespace ng editor_t (buffer_t& buffer); editor_t (document::document_ptr document); - void perform (action_t action, layout_t const* layout = NULL); + void perform (action_t action, layout_t const* layout = NULL, bool indentCorrections = false); bool disallow_tab_expansion () const; void insert (std::string const& str, bool selectInsertion = false); - void insert_with_pairing (std::string const& str); + void insert_with_pairing (std::string const& str, bool indentCorrections = false); void move_selection_to (ng::index_t const& index, bool selectInsertion = true); ranges_t replace (std::string const& searchFor, std::string const& replaceWith, find::options_t options = find::none, bool searchOnlySelection = false); void delete_tab_trigger (std::string const& str);