# This file tests UNDO command.

# Enable IME
SEND_KEY	ON

# Set to Qwerty kana mode.
SET_MOBILE_REQUEST
SET_CONFIG	session_keymap	MOBILE
UPDATE_MOBILE_KEYBOARD	QWERTY_MOBILE_TO_HIRAGANA	SPACE_OR_CONVERT_KEEPING_COMPOSITION
SWITCH_INPUT_MODE	HIRAGANA

# Case 1: Undo for partial commit

# Send keys "watasinoneko" to get composition "わたしのねこ"
RESET_CONTEXT
SEND_KEYS	watasinoneko
EXPECT_PREEDIT	わたしのねこ
# In this test, EXPECT_IN_ALL_CANDIDATE_WORDS is used to confirm the cursor position.
EXPECT_IN_ALL_CANDIDATE_WORDS	わたしのねこ

# Submit 私 to consume "わたし"
EXPECT_IN_ALL_CANDIDATE_WORDS	私
SUBMIT_CANDIDATE_BY_VALUE	私
EXPECT_PREEDIT	のねこ
EXPECT_IN_ALL_CANDIDATE_WORDS	のねこ

# Perform Undo to revive the original preedit.
SEND_KEY	CTRL BACKSPACE
EXPECT_PREEDIT	わたしのねこ
EXPECT_IN_ALL_CANDIDATE_WORDS	わたしのねこ


# Case 2: Undo for partial commit: with cursor move

# Send keys "watasino" to get composition "わたしの"
RESET_CONTEXT
SEND_KEYS	watasino
EXPECT_PREEDIT	わたしの
EXPECT_IN_ALL_CANDIDATE_WORDS	わたしの

# Submit 1st candidate
SEND_KEY	LEFT
EXPECT_IN_ALL_CANDIDATE_WORDS	わたし
SEND_KEY	LEFT
EXPECT_IN_ALL_CANDIDATE_WORDS	わた
SUBMIT_CANDIDATE	0
EXPECT_PREEDIT	しの
EXPECT_IN_ALL_CANDIDATE_WORDS	しの

# Perform Undo to revive the original preedit.
SEND_KEY	CTRL BACKSPACE
EXPECT_PREEDIT	わたしの
# Cursor position is also revived.
EXPECT_IN_ALL_CANDIDATE_WORDS	わた

# Once any operations are performed, Undo operation should be ignored.
SEND_KEY	RIGHT
EXPECT_PREEDIT	わたしの
EXPECT_IN_ALL_CANDIDATE_WORDS	わたし
SEND_KEY	CTRL BACKSPACE
EXPECT_PREEDIT	わたしの
EXPECT_IN_ALL_CANDIDATE_WORDS	わたし


# Case 3: Multiple undo

# Send keys "watasino" to get composition "わたしの"
RESET_CONTEXT
SEND_KEYS	watasino
EXPECT_PREEDIT	わたしの
EXPECT_IN_ALL_CANDIDATE_WORDS	わたしの

# 1st commit
SEND_KEY	LEFT
EXPECT_IN_ALL_CANDIDATE_WORDS	わたし
SEND_KEY	LEFT
EXPECT_IN_ALL_CANDIDATE_WORDS	わた
SUBMIT_CANDIDATE	0
EXPECT_PREEDIT	しの
EXPECT_IN_ALL_CANDIDATE_WORDS	しの

# 2nd commit
SUBMIT_CANDIDATE_BY_VALUE	し
EXPECT_PREEDIT	の
EXPECT_IN_ALL_CANDIDATE_WORDS	の

# 1st Undo for 2nd commit works.
SEND_KEY	CTRL BACKSPACE
EXPECT_PREEDIT	しの
EXPECT_IN_ALL_CANDIDATE_WORDS	しの

# 2nd Undo for 1st commit
SEND_KEY	CTRL BACKSPACE
EXPECT_PREEDIT	わたしの
EXPECT_IN_ALL_CANDIDATE_WORDS	わた


# Case 4: Once any operations are performed, Undo operation should be ignored.

RESET_CONTEXT
SEND_KEYS	watasinoneko
EXPECT_PREEDIT	わたしのねこ
EXPECT_IN_ALL_CANDIDATE_WORDS	私
SUBMIT_CANDIDATE_BY_VALUE	私
EXPECT_PREEDIT	のねこ
EXPECT_IN_ALL_CANDIDATE_WORDS	のねこ

# "SEND_KEY	LEFT" should invalidate Undo stack as it changes Preedit (cursor position).
SEND_KEY	LEFT
EXPECT_PREEDIT	のねこ
EXPECT_IN_ALL_CANDIDATE_WORDS	のね
SEND_KEY	CTRL BACKSPACE
# Nothing should be changed.
EXPECT_PREEDIT	のねこ
EXPECT_IN_ALL_CANDIDATE_WORDS	のね

