Move check for indent corrections to OakTextView

This makes it easier to introduce a UI setting for the option.
This commit is contained in:
Allan Odgaard
2012-09-17 23:33:22 +02:00
parent 08666a37ba
commit 130d0a168d
4 changed files with 18 additions and 12 deletions

View File

@@ -99,6 +99,7 @@ PUBLIC @interface OakTextView : OakView <NSTextInput, NSTextFieldDelegate>
@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;

View File

@@ -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:)]; }

View File

@@ -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;

View File

@@ -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);