From 82744018b5f69c6e289ac5aebec882279090677a Mon Sep 17 00:00:00 2001 From: pit-ray Date: Thu, 4 Jan 2024 21:10:20 +0900 Subject: [PATCH] remove autofocus_textarea and keep compatibility --- CMakeLists.txt | 2 +- docs/cheat_sheet/functions/index.md | 2 +- docs/cheat_sheet/options/index.md | 8 +--- src/bind/mode/change_mode.cpp | 17 +------ src/bind/mode/change_mode.hpp | 7 +-- src/bind/mode/options.cpp | 74 ----------------------------- src/bind/mode/options.hpp | 20 -------- src/bind/mode/text_area_scanner.cpp | 71 --------------------------- src/bind/mode/text_area_scanner.hpp | 19 -------- src/bind/syscmd/source.cpp | 20 ++++++-- src/core/settable.cpp | 1 - 11 files changed, 21 insertions(+), 220 deletions(-) delete mode 100644 src/bind/mode/options.cpp delete mode 100644 src/bind/mode/options.hpp delete mode 100644 src/bind/mode/text_area_scanner.cpp delete mode 100644 src/bind/mode/text_area_scanner.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 37c58c18..3d214807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.6.0) -project(win-vind VERSION 5.7.0) +project(win-vind VERSION 5.8.0) set(INTERNAL_VERSION ${PROJECT_VERSION}.0) if(NOT CMAKE_BUILD_TYPE) diff --git a/docs/cheat_sheet/functions/index.md b/docs/cheat_sheet/functions/index.md index 3a98f818..b7ebd47b 100644 --- a/docs/cheat_sheet/functions/index.md +++ b/docs/cheat_sheet/functions/index.md @@ -501,7 +501,7 @@ In order to change the grid size, set the size with `gridmove_size` option. It a Select the text area closest to the cursor and move the mouse cursor over it. If there are multiple text areas, the selection is based on the minimum Euclidean distance between the mouse cursor and the center point of the bounding box of the text area. -In the previous version of win-vind, this function was attached to the Editor Normal Mode as the `autofocus_textarea` option, but it is now independent. Currently, the `autofocus_textarea` option is deprecated. For compatibility, `autofocus_textarea` defines a mapping to ``. +In the previous version of win-vind, this function was attached to the Editor Normal Mode as the `autofocus_textarea` option, but it is now independent. Currently, the `autofocus_textarea` option is deprecated. For compatibility, `autofocus_textarea` defines a mapping such as `autocmd EdiNormalEnter * `.

diff --git a/docs/cheat_sheet/options/index.md b/docs/cheat_sheet/options/index.md index 2701a0e1..c5911c8e 100644 --- a/docs/cheat_sheet/options/index.md +++ b/docs/cheat_sheet/options/index.md @@ -292,12 +292,6 @@ Width of block style caret on solid mode ## AutoFocus -### **`autofocus_textarea`** -**type**: bool, **default**: false -Automatically focus on the nearest text area when switching to **Editor Normal Mode** - -


- ### **`autotrack_popup`** **type**: bool, **default**: false It is one of standard options on Windows. For example, if shown **Are you sure you want to move this file to the Recycle Bin?**, it automatically moves the cursor to the popup window. @@ -307,7 +301,7 @@ It is one of standard options on Windows. For example, if shown **Are you sure y ### **`uiacachebuild`** **type**: bool, **default**: false -EasyClick and `autofocus_textarea` are slow because they scan the UI object after being called. If this option is enabled, scanning is done asynchronously and cache is used as a result. Using the cache is 30 times faster than scanning linearly, but the location information, etc. may not always be correct. +[easyclick](../functions/#easyclick) and [focus_textarea](../functions/#focus_textarea) are slow because they scan the UI object after being called. If this option is enabled, scanning is done asynchronously and cache is used as a result. Using the cache is 30 times faster than scanning linearly, but the location information, etc. may not always be correct.
diff --git a/src/bind/mode/change_mode.cpp b/src/bind/mode/change_mode.cpp index 5dd89853..3e9f44c4 100644 --- a/src/bind/mode/change_mode.cpp +++ b/src/bind/mode/change_mode.cpp @@ -9,7 +9,6 @@ #include "core/settable.hpp" #include "opt/uiacachebuild.hpp" #include "opt/vcmdline.hpp" -#include "options.hpp" #include "util/debug.hpp" #include "util/def.hpp" #include "util/mouse.hpp" @@ -102,16 +101,10 @@ namespace vind ac.apply(core::get_enter_event(core::Mode::GUI_VISUAL)) ; } - // All instances share TextAreaScanner to keep staticity of sprocess. - TextAreaScanner ToEdiNormal::scanner_ ; - //ToEdiNormal ToEdiNormal::ToEdiNormal() : BindedFuncVoid("to_edi_normal") - { - opt::AsyncUIACacheBuilder::register_properties( - scanner_.get_properties()) ; - } + {} void ToEdiNormal::sprocess( std::uint16_t UNUSED(count), const std::string& UNUSED(args), @@ -138,14 +131,6 @@ namespace vind opt::VCmdLine::print(opt::GeneralMessage("-- EDI NORMAL --")) ; } - auto& settable = core::SetTable::get_instance() ; - if(settable.get("autofocus_textarea").get()) { - if(auto hwnd = util::get_foreground_window()) { - auto pos = util::get_cursor_pos() ; - focus_nearest_textarea(hwnd, pos, scanner_) ; - } - } - ac.apply(core::get_enter_event(Mode::EDI_NORMAL)) ; } diff --git a/src/bind/mode/change_mode.hpp b/src/bind/mode/change_mode.hpp index 35f71d08..480bc288 100644 --- a/src/bind/mode/change_mode.hpp +++ b/src/bind/mode/change_mode.hpp @@ -2,7 +2,6 @@ #define _CHANGE_MODE_HPP #include "bind/bindedfunc.hpp" -#include "text_area_scanner.hpp" namespace vind { @@ -44,11 +43,7 @@ namespace vind } } ; - class ToEdiNormal : public BindedFuncVoid { - private: - static TextAreaScanner scanner_ ; - - public: + struct ToEdiNormal : public BindedFuncVoid { explicit ToEdiNormal() ; static void sprocess( std::uint16_t count, diff --git a/src/bind/mode/options.cpp b/src/bind/mode/options.cpp deleted file mode 100644 index d3d1032b..00000000 --- a/src/bind/mode/options.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "options.hpp" - -#include "core/settable.hpp" -#include "opt/uiacachebuild.hpp" -#include "util/box2d.hpp" -#include "util/debug.hpp" -#include "util/def.hpp" -#include "util/rect.hpp" -#include "util/uia.hpp" -#include "util/winwrap.hpp" - -#include - - -#undef max - - -namespace vind -{ - namespace bind - { - void focus_nearest_textarea( - HWND hwnd, - const util::Point2D& point, - TextAreaScanner& instance) { - - std::vector editables{} ; - - auto& settable = core::SetTable::get_instance() ; - if(settable.get("uiacachebuild").get()) { - auto root_elem = opt::AsyncUIACacheBuilder::get_root_element(hwnd) ; - instance.scan(root_elem, editables) ; - } - else { - instance.scan(hwnd, editables) ; - } - - if(editables.empty()) { - return ; - } - - if(editables.size() == 1) { - if(util::is_failed(editables.front()->SetFocus())) { - throw RUNTIME_EXCEPT("SetFocus Failed.") ; - } - return ; - } - - util::SmartElement nearest ; - auto min_distance = std::numeric_limits::max() ; - - for(auto& elem : editables) { - // scan GUI objects only at leaves in tree. - util::Box2D box ; - if(util::is_failed(elem->get_CachedBoundingRectangle(&box.data()))) { - throw RUNTIME_EXCEPT("Could not get the a rectangle of a element.") ; - } - - auto distance = util::l2_distance_nosq( - point.x(), point.y(), - box.center_x(), box.center_y()) / 100 ; - - if(min_distance > distance) { - nearest = elem ; - min_distance = distance ; - } - } - - if(util::is_failed(nearest->SetFocus())) { - throw RUNTIME_EXCEPT("SetFocus Failed.") ; - } - } - } -} diff --git a/src/bind/mode/options.hpp b/src/bind/mode/options.hpp deleted file mode 100644 index 76387d2a..00000000 --- a/src/bind/mode/options.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _OPTIONS_HPP -#define _OPTIONS_HPP - -#include "text_area_scanner.hpp" -#include "util/point2d.hpp" - - -namespace vind -{ - namespace bind - { - void focus_nearest_textarea( - HWND hwnd, - const util::Point2D& point, - TextAreaScanner& instance) ; - - } -} - -#endif diff --git a/src/bind/mode/text_area_scanner.cpp b/src/bind/mode/text_area_scanner.cpp deleted file mode 100644 index 4f6abac3..00000000 --- a/src/bind/mode/text_area_scanner.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "text_area_scanner.hpp" - -#include "core/errlogger.hpp" -#include "util/debug.hpp" -#include "util/def.hpp" -#include "util/winwrap.hpp" - - -namespace vind -{ - namespace bind - { - TextAreaScanner::TextAreaScanner() - : UIWalker{ - UIA_IsTextPatternAvailablePropertyId, - UIA_IsValuePatternAvailablePropertyId, - UIA_HasKeyboardFocusPropertyId, - UIA_ValueIsReadOnlyPropertyId - } - { - UIWalker::enable_fullcontrol() ; - } - - bool TextAreaScanner::pinpoint_element(const util::SmartElement& elem) { - BOOL flag ; - if(util::is_failed(elem->get_CachedHasKeyboardFocus(&flag))) { - throw RUNTIME_EXCEPT("Could not get a cached property value: HasKeyboardFocus.") ; - } - return flag == TRUE ; - } - - bool TextAreaScanner::filter_element(const util::SmartElement& elem) { - VARIANT val ; - - if(util::is_failed(elem->GetCachedPropertyValue( - UIA_ValueIsReadOnlyPropertyId, &val))) { - throw RUNTIME_EXCEPT("Could not get a chached property value: IsReadOnly.") ; - } - if(val.vt != VT_BOOL) { - return false ; - } - if(val.boolVal == VARIANT_TRUE) { - return false ; - } - - if(util::is_failed(elem->GetCachedPropertyValue( - UIA_IsTextPatternAvailablePropertyId, &val))) { - throw RUNTIME_EXCEPT("Could not get a chached property value: IsTextPatternAvailable.") ; - } - if(val.vt != VT_BOOL) { - return false ; - } - if(val.boolVal == VARIANT_FALSE) { - return false ; - } - - if(util::is_failed(elem->GetCachedPropertyValue( - UIA_IsValuePatternAvailablePropertyId, &val))) { - throw RUNTIME_EXCEPT("Could not get a chached property value: IsValuePatternAvailable.") ; - } - if(val.vt != VT_BOOL) { - return false ; - } - if(val.boolVal == VARIANT_FALSE) { - return false ; - } - - return true ; - } - } -} diff --git a/src/bind/mode/text_area_scanner.hpp b/src/bind/mode/text_area_scanner.hpp deleted file mode 100644 index 462f783a..00000000 --- a/src/bind/mode/text_area_scanner.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _BIND_MODE_OPTIONS_HPP -#define _BIND_MODE_OPTIONS_HPP - -#include "util/uiwalker.hpp" - - -namespace vind -{ - namespace bind - { - struct TextAreaScanner : public util::UIWalker { - explicit TextAreaScanner() ; - virtual bool pinpoint_element(const util::SmartElement& elem) override ; - virtual bool filter_element(const util::SmartElement& elem) override ; - } ; - } -} - -#endif diff --git a/src/bind/syscmd/source.cpp b/src/bind/syscmd/source.cpp index 5e923eb7..7d94065c 100644 --- a/src/bind/syscmd/source.cpp +++ b/src/bind/syscmd/source.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -85,7 +86,7 @@ namespace return target_repo_path / ".vindrc" ; } - std::string to_compatible(std::string text) { + void to_compatible(std::string& cmd, std::string& args) { std::vector> compatible { {"system_command_comclear", "comclear"}, {"system_command_command", "command"}, @@ -116,9 +117,17 @@ namespace {"", ""}, } ; for(auto& [from, to] : compatible) { - text = util::replace_all(text, from, to) ; + args = util::replace_all(args, from, to) ; + } + + if(args.find("noautofocus_textarea") != std::string::npos) { + cmd.clear() ; + args.clear() ; + } + else if(args.find("autofocus_textarea") != std::string::npos) { + cmd = "autocmd" ; + args = "EdiNormalEnter * " ; } - return text ; } void do_runcommand( @@ -266,7 +275,10 @@ namespace vind } cmd = util::A2a(cmd) ; - line_args = to_compatible(line_args) ; + to_compatible(cmd, line_args) ; + if(cmd.empty()) { + continue ; + } if(!loaded_default_) { loaded_default_ = true ; diff --git a/src/core/settable.cpp b/src/core/settable.cpp index a8bf4dc2..9294692f 100644 --- a/src/core/settable.cpp +++ b/src/core/settable.cpp @@ -13,7 +13,6 @@ namespace Param("arrangewin_ignore", ""), - Param("autofocus_textarea", false), Param("autotrack_popup", false), Param("blockstylecaret", false),