Skip to content
Permalink
Browse files

Set text direction on scintilla instances

Closes #6
  • Loading branch information...
dail8859 committed Jan 6, 2017
1 parent 3c80850 commit 8fed28f8ffe494c5e68a02010fddcdac4b4d3f74
Showing with 35 additions and 3 deletions.
  1. +6 −2 docs_gen/genEditor.lua
  2. +1 −1 src/LuaConsole.cpp
  3. +13 −0 src/NppExtensionAPI.cpp
  4. +1 −0 src/NppExtensionAPI.h
  5. +14 −0 src/SciTE/LuaExtension.cpp
@@ -25,7 +25,7 @@ for m in editor:match([[\A.*<!--\+\+Autogenerated -->\r\n]], SCFIND_REGEXP | SCF
--- Helper Methods
-- @section helpermethods
--- Gets the text within a range
--- Gets the text within a range.
-- @function textrange
-- @tparam int startPos
-- @tparam int endPos
@@ -61,11 +61,15 @@ for m in editor:match([[\A.*<!--\+\+Autogenerated -->\r\n]], SCFIND_REGEXP | SCF
-- @tparam int pos position to insert the text
-- @tparam string text text to insert
--- Removes the text in the range
--- Removes the text in the range.
-- @function remove
-- @tparam int startPos
-- @tparam int endPos
--- Sets the text direction.
-- @function set_text_direction
-- @tparam string direction either "RTL" or "LTR"
]]) end

-- Remove everything after <!----Autogenerated -->
@@ -27,7 +27,7 @@
#define INDIC_BRACEBADLIGHT INDIC_CONTAINER + 1

// Extra helper functions not from the IFace tables
static const std::vector<std::string> moreSciFuncs = { "append", "findtext", "match", "remove", "textrange" };
static const std::vector<std::string> moreSciFuncs = { "append", "findtext", "match", "remove", "set_text_direction", "textrange" };
static const std::vector<std::string> moreNppFuncs = { "AddEventHandler", "AddShortcut", "ClearConsole", "ConstantName", "RemoveAllEventHandlers", "RemoveEventHandler", "SendEditor", "WriteError" };

// Copied from Scintilla
@@ -63,6 +63,19 @@ void NppExtensionAPI::Insert(NppExtensionAPI::Pane p, int pos, const char *s) {
this->Send(p, SCI_INSERTTEXT, pos, reinterpret_cast<LPARAM>(s));
}

void NppExtensionAPI::SetTextDirection(NppExtensionAPI::Pane p, bool rtl) {
HWND hwnd = reinterpret_cast<HWND>(scis[p].GetID());
long exStyle = static_cast<long>(::GetWindowLongPtr(hwnd, GWL_EXSTYLE));
exStyle = rtl ? (exStyle | WS_EX_LAYOUTRTL) : (exStyle & (~WS_EX_LAYOUTRTL));
::SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle);

// Toggle the wrap mode back and forth to fix the problem of mirrored characters
// This was taken from N++
bool isWrapped = this->Send(p, SCI_GETWRAPMODE) == SC_WRAP_WORD;
this->Send(p, SCI_SETWRAPMODE, !isWrapped);
this->Send(p, SCI_SETWRAPMODE, isWrapped);
}

void NppExtensionAPI::Trace(const char *s) {
cd->writeText(strlen(s), s);
}
@@ -64,6 +64,7 @@ class NppExtensionAPI final {
char *Range(Pane p, int start, int end);
void Remove(Pane p, int start, int end);
void Insert(Pane p, int pos, const char *s);
void SetTextDirection(Pane p, bool rtl);
void Trace(const char *s);
void TraceError(const char *s);
void Tracef(const char *fmt, ...);
@@ -587,6 +587,18 @@ static int cf_pane_append(lua_State *L) {
return 0;
}

static int cf_pane_set_text_dir(lua_State *L) {
NppExtensionAPI::Pane p = check_pane_object(L, 1);
const char *s = luaL_checkstring(L, 2);

if (strcmp(s, "RTL") != 0 && strcmp(s, "LTR") != 0)
raise_error(L, "Invalid text direction. Must be \"RTL\" or \"LTR\"");

host->SetTextDirection(p, strcmp(s, "RTL") == 0);

return 0;
}

static int cf_pane_findtext(lua_State *L) {
NppExtensionAPI::Pane p = check_pane_object(L, 1);

@@ -1302,6 +1314,8 @@ void push_pane_object(lua_State *L, NppExtensionAPI::Pane p) {
lua_setfield(L, -2, "remove");
lua_pushcfunction(L, cf_pane_append);
lua_setfield(L, -2, "append");
lua_pushcfunction(L, cf_pane_set_text_dir);
lua_setfield(L, -2, "set_text_direction");

lua_pushcfunction(L, cf_pane_match_generator);
lua_pushcclosure(L, cf_pane_match, 1);

0 comments on commit 8fed28f

Please sign in to comment.
You can’t perform that action at this time.