Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
itdan3344
stb
提交
2c71a432
S
stb
项目概览
itdan3344
/
stb
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
stb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c71a432
编写于
8月 27, 2016
作者:
S
Sean Barrett
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'working'
上级
50ec4026
bde8f7c1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
30 deletion
+41
-30
stb_textedit.h
stb_textedit.h
+41
-30
未找到文件。
stb_textedit.h
浏览文件 @
2c71a432
...
...
@@ -148,15 +148,17 @@
// STB_TEXTEDIT_K_REDO keyboard input to perform redo
//
// Optional:
// STB_TEXTEDIT_K_INSERT keyboard input to toggle insert mode
// STB_TEXTEDIT_IS_SPACE(ch) true if character is whitespace (e.g. 'isspace'),
// required for WORDLEFT/WORDRIGHT
// STB_TEXTEDIT_K_WORDLEFT keyboard input to move cursor left one word // e.g. ctrl-LEFT
// STB_TEXTEDIT_K_WORDRIGHT keyboard input to move cursor right one word // e.g. ctrl-RIGHT
// STB_TEXTEDIT_K_LINESTART2 secondary keyboard input to move cursor to start of line
// STB_TEXTEDIT_K_LINEEND2 secondary keyboard input to move cursor to end of line
// STB_TEXTEDIT_K_TEXTSTART2 secondary keyboard input to move cursor to start of text
// STB_TEXTEDIT_K_TEXTEND2 secondary keyboard input to move cursor to end of text
// STB_TEXTEDIT_K_INSERT keyboard input to toggle insert mode
// STB_TEXTEDIT_IS_SPACE(ch) true if character is whitespace (e.g. 'isspace'),
// required for default WORDLEFT/WORDRIGHT handlers
// STB_TEXTEDIT_MOVEWORDLEFT(obj,i) custom handler for WORDLEFT, returns index to move cursor to
// STB_TEXTEDIT_MOVEWORDRIGHT(obj,i) custom handler for WORDRIGHT, returns index to move cursor to
// STB_TEXTEDIT_K_WORDLEFT keyboard input to move cursor left one word // e.g. ctrl-LEFT
// STB_TEXTEDIT_K_WORDRIGHT keyboard input to move cursor right one word // e.g. ctrl-RIGHT
// STB_TEXTEDIT_K_LINESTART2 secondary keyboard input to move cursor to start of line
// STB_TEXTEDIT_K_LINEEND2 secondary keyboard input to move cursor to end of line
// STB_TEXTEDIT_K_TEXTSTART2 secondary keyboard input to move cursor to start of text
// STB_TEXTEDIT_K_TEXTEND2 secondary keyboard input to move cursor to end of text
//
// Todo:
// STB_TEXTEDIT_K_PGUP keyboard input to move cursor up a page
...
...
@@ -609,15 +611,16 @@ static void stb_textedit_move_to_last(STB_TEXTEDIT_STRING *str, STB_TexteditStat
}
#ifdef STB_TEXTEDIT_IS_SPACE
static
int
is_word_boundary
(
STB_TEXTEDIT_STRING
*
_str
,
int
_
idx
)
static
int
is_word_boundary
(
STB_TEXTEDIT_STRING
*
str
,
int
idx
)
{
return
_idx
>
0
?
(
STB_TEXTEDIT_IS_SPACE
(
STB_TEXTEDIT_GETCHAR
(
_str
,
_idx
-
1
)
)
&&
!
STB_TEXTEDIT_IS_SPACE
(
STB_TEXTEDIT_GETCHAR
(
_str
,
_
idx
)
)
)
:
1
;
return
idx
>
0
?
(
STB_TEXTEDIT_IS_SPACE
(
STB_TEXTEDIT_GETCHAR
(
str
,
idx
-
1
)
)
&&
!
STB_TEXTEDIT_IS_SPACE
(
STB_TEXTEDIT_GETCHAR
(
str
,
idx
)
)
)
:
1
;
}
static
int
stb_textedit_move_to_word_previous
(
STB_TEXTEDIT_STRING
*
_str
,
STB_TexteditState
*
_state
)
#ifndef STB_TEXTEDIT_MOVEWORDLEFT
static
int
stb_textedit_move_to_word_previous
(
STB_TEXTEDIT_STRING
*
str
,
int
c
)
{
int
c
=
_state
->
cursor
-
1
;
while
(
c
>=
0
&&
!
is_word_boundary
(
_
str
,
c
)
)
--
c
;
// always move at least one character
while
(
c
>=
0
&&
!
is_word_boundary
(
str
,
c
)
)
--
c
;
if
(
c
<
0
)
...
...
@@ -625,12 +628,15 @@ static int stb_textedit_move_to_word_previous( STB_TEXTEDIT_STRING *_str, STB_Te
return
c
;
}
#define STB_TEXTEDIT_MOVEWORDLEFT stb_textedit_move_to_word_previous
#endif
static
int
stb_textedit_move_to_word_next
(
STB_TEXTEDIT_STRING
*
_str
,
STB_TexteditState
*
_state
)
#ifndef STB_TEXTEDIT_MOVEWORDRIGHT
static
int
stb_textedit_move_to_word_next
(
STB_TEXTEDIT_STRING
*
str
,
int
c
)
{
const
int
len
=
STB_TEXTEDIT_STRINGLEN
(
_str
);
int
c
=
_state
->
cursor
+
1
;
while
(
c
<
len
&&
!
is_word_boundary
(
_
str
,
c
)
)
++
c
;
// always move at least one character
while
(
c
<
len
&&
!
is_word_boundary
(
str
,
c
)
)
++
c
;
if
(
c
>
len
)
...
...
@@ -638,6 +644,9 @@ static int stb_textedit_move_to_word_next( STB_TEXTEDIT_STRING *_str, STB_Texted
return
c
;
}
#define STB_TEXTEDIT_MOVEWORDRIGHT stb_textedit_move_to_word_next
#endif
#endif
// update selection and cursor to match each other
...
...
@@ -759,21 +768,12 @@ retry:
state
->
has_preferred_x
=
0
;
break
;
#ifdef STB_TEXTEDIT_
IS_SPACE
#ifdef STB_TEXTEDIT_
MOVEWORDLEFT
case
STB_TEXTEDIT_K_WORDLEFT
:
if
(
STB_TEXT_HAS_SELECTION
(
state
))
stb_textedit_move_to_first
(
state
);
else
{
state
->
cursor
=
stb_textedit_move_to_word_previous
(
str
,
state
);
stb_textedit_clamp
(
str
,
state
);
}
break
;
case
STB_TEXTEDIT_K_WORDRIGHT
:
if
(
STB_TEXT_HAS_SELECTION
(
state
))
stb_textedit_move_to_last
(
str
,
state
);
else
{
state
->
cursor
=
stb_textedit_move_to_word_next
(
str
,
state
);
state
->
cursor
=
STB_TEXTEDIT_MOVEWORDLEFT
(
str
,
state
->
cursor
);
stb_textedit_clamp
(
str
,
state
);
}
break
;
...
...
@@ -782,17 +782,28 @@ retry:
if
(
!
STB_TEXT_HAS_SELECTION
(
state
)
)
stb_textedit_prep_selection_at_cursor
(
state
);
state
->
cursor
=
stb_textedit_move_to_word_previous
(
str
,
state
);
state
->
cursor
=
STB_TEXTEDIT_MOVEWORDLEFT
(
str
,
state
->
cursor
);
state
->
select_end
=
state
->
cursor
;
stb_textedit_clamp
(
str
,
state
);
break
;
#endif
#ifdef STB_TEXTEDIT_MOVEWORDRIGHT
case
STB_TEXTEDIT_K_WORDRIGHT
:
if
(
STB_TEXT_HAS_SELECTION
(
state
))
stb_textedit_move_to_last
(
str
,
state
);
else
{
state
->
cursor
=
STB_TEXTEDIT_MOVEWORDRIGHT
(
str
,
state
->
cursor
);
stb_textedit_clamp
(
str
,
state
);
}
break
;
case
STB_TEXTEDIT_K_WORDRIGHT
|
STB_TEXTEDIT_K_SHIFT
:
if
(
!
STB_TEXT_HAS_SELECTION
(
state
)
)
stb_textedit_prep_selection_at_cursor
(
state
);
state
->
cursor
=
stb_textedit_move_to_word_next
(
str
,
state
);
state
->
cursor
=
STB_TEXTEDIT_MOVEWORDRIGHT
(
str
,
state
->
cursor
);
state
->
select_end
=
state
->
cursor
;
stb_textedit_clamp
(
str
,
state
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录