Skip to content

Commit

Permalink
remove autofocus_textarea and keep compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Jan 4, 2024
1 parent 19f1807 commit 8274401
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 220 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/cheat_sheet/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<focus_textarea><to_edi_normal>`.
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 * <focus_textarea>`.

<p align="center">
<img src="{{ site.url }}/imgs/focus_textarea.png" class="img-fluid">
Expand Down
8 changes: 1 addition & 7 deletions docs/cheat_sheet/options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

<hr class="dash">

### **`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.
Expand All @@ -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.

<hr class="dash">

Expand Down
17 changes: 1 addition & 16 deletions src/bind/mode/change_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand All @@ -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<bool>()) {
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)) ;
}

Expand Down
7 changes: 1 addition & 6 deletions src/bind/mode/change_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _CHANGE_MODE_HPP

#include "bind/bindedfunc.hpp"
#include "text_area_scanner.hpp"

namespace vind
{
Expand Down Expand Up @@ -44,11 +43,7 @@ namespace vind
}
} ;

class ToEdiNormal : public BindedFuncVoid<ToEdiNormal> {
private:
static TextAreaScanner scanner_ ;

public:
struct ToEdiNormal : public BindedFuncVoid<ToEdiNormal> {
explicit ToEdiNormal() ;
static void sprocess(
std::uint16_t count,
Expand Down
74 changes: 0 additions & 74 deletions src/bind/mode/options.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/bind/mode/options.hpp

This file was deleted.

71 changes: 0 additions & 71 deletions src/bind/mode/text_area_scanner.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions src/bind/mode/text_area_scanner.hpp

This file was deleted.

20 changes: 16 additions & 4 deletions src/bind/syscmd/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdexcept>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -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<std::pair<std::string, std::string>> compatible {
{"system_command_comclear", "comclear"},
{"system_command_command", "command"},
Expand Down Expand Up @@ -116,9 +117,17 @@ namespace
{"<easy_click_hover>", "<easyclick>"},
} ;
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 * <focus_textarea>" ;
}
return text ;
}

void do_runcommand(
Expand Down Expand Up @@ -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 ;
Expand Down
1 change: 0 additions & 1 deletion src/core/settable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace

Param("arrangewin_ignore", ""),

Param("autofocus_textarea", false),
Param("autotrack_popup", false),

Param("blockstylecaret", false),
Expand Down

0 comments on commit 8274401

Please sign in to comment.