TextViewTests.cs 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. using System;
  2. using System.Linq;
  3. using Xunit;
  4. namespace Terminal.Gui.Views {
  5. public class TextViewTests {
  6. private TextView _textView;
  7. public TextViewTests ()
  8. {
  9. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  10. // 1 2 3
  11. // 01234567890123456789012345678901=32 (Length)
  12. var txt = "TAB to jump between text fields.";
  13. var buff = new byte [txt.Length];
  14. for (int i = 0; i < txt.Length; i++) {
  15. buff [i] = (byte)txt [i];
  16. }
  17. var ms = new System.IO.MemoryStream (buff).ToArray ();
  18. _textView = new TextView () { Width = 30, Height = 10 };
  19. _textView.Text = ms;
  20. }
  21. [Fact]
  22. public void Changing_Selection_Or_CursorPosition_Update_SelectedLength_And_SelectedText ()
  23. {
  24. _textView.SelectionStartColumn = 2;
  25. _textView.SelectionStartRow = 0;
  26. Assert.Equal (0, _textView.CursorPosition.X);
  27. Assert.Equal (0, _textView.CursorPosition.Y);
  28. Assert.Equal (2, _textView.SelectedLength);
  29. Assert.Equal ("TA", _textView.SelectedText);
  30. _textView.CursorPosition = new Point (20, 0);
  31. Assert.Equal (2, _textView.SelectionStartColumn);
  32. Assert.Equal (0, _textView.SelectionStartRow);
  33. Assert.Equal (18, _textView.SelectedLength);
  34. Assert.Equal ("B to jump between ", _textView.SelectedText);
  35. }
  36. [Fact]
  37. public void Selection_With_Value_Less_Than_Zero_Changes_To_Zero ()
  38. {
  39. _textView.SelectionStartColumn = -2;
  40. _textView.SelectionStartRow = -2;
  41. Assert.Equal (0, _textView.SelectionStartColumn);
  42. Assert.Equal (0, _textView.SelectionStartRow);
  43. Assert.Equal (0, _textView.SelectedLength);
  44. Assert.Equal ("", _textView.SelectedText);
  45. }
  46. [Fact]
  47. public void Selection_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  48. {
  49. _textView.CursorPosition = new Point (2, 0);
  50. _textView.SelectionStartColumn = 33;
  51. _textView.SelectionStartRow = 1;
  52. Assert.Equal (32, _textView.SelectionStartColumn);
  53. Assert.Equal (0, _textView.SelectionStartRow);
  54. Assert.Equal (30, _textView.SelectedLength);
  55. Assert.Equal ("B to jump between text fields.", _textView.SelectedText);
  56. }
  57. [Fact]
  58. public void Selection_With_Empty_Text ()
  59. {
  60. _textView = new TextView ();
  61. _textView.CursorPosition = new Point (2, 0);
  62. _textView.SelectionStartColumn = 33;
  63. _textView.SelectionStartRow = 1;
  64. Assert.Equal (0, _textView.SelectionStartColumn);
  65. Assert.Equal (0, _textView.SelectionStartRow);
  66. Assert.Equal (0, _textView.SelectedLength);
  67. Assert.Equal ("", _textView.SelectedText);
  68. }
  69. [Fact]
  70. public void Selection_And_CursorPosition_With_Value_Greater_Than_Text_Length_Changes_Both_To_Text_Length ()
  71. {
  72. _textView.CursorPosition = new Point (33, 2);
  73. _textView.SelectionStartColumn = 33;
  74. _textView.SelectionStartRow = 33;
  75. Assert.Equal (32, _textView.CursorPosition.X);
  76. Assert.Equal (0, _textView.CursorPosition.Y);
  77. Assert.Equal (32, _textView.SelectionStartColumn);
  78. Assert.Equal (0, _textView.SelectionStartRow);
  79. Assert.Equal (0, _textView.SelectedLength);
  80. Assert.Equal ("", _textView.SelectedText);
  81. }
  82. [Fact]
  83. public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
  84. {
  85. _textView.CursorPosition = new Point (-1, -1);
  86. Assert.Equal (0, _textView.CursorPosition.X);
  87. Assert.Equal (0, _textView.CursorPosition.Y);
  88. Assert.Equal (0, _textView.SelectedLength);
  89. Assert.Equal ("", _textView.SelectedText);
  90. }
  91. [Fact]
  92. public void CursorPosition_With_Value_Greater_Than_Text_Length_Changes_To_Text_Length ()
  93. {
  94. _textView.CursorPosition = new Point (33, 1);
  95. Assert.Equal (32, _textView.CursorPosition.X);
  96. Assert.Equal (0, _textView.CursorPosition.Y);
  97. Assert.Equal (0, _textView.SelectedLength);
  98. Assert.Equal ("", _textView.SelectedText);
  99. }
  100. [Fact]
  101. public void WordForward_With_No_Selection ()
  102. {
  103. _textView.CursorPosition = new Point (0, 0);
  104. var iteration = 0;
  105. while (_textView.CursorPosition.X < _textView.Text.Length) {
  106. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  107. switch (iteration) {
  108. case 0:
  109. Assert.Equal (4, _textView.CursorPosition.X);
  110. Assert.Equal (0, _textView.CursorPosition.Y);
  111. Assert.Equal (0, _textView.SelectionStartColumn);
  112. Assert.Equal (0, _textView.SelectionStartRow);
  113. Assert.Equal (0, _textView.SelectedLength);
  114. Assert.Equal ("", _textView.SelectedText);
  115. break;
  116. case 1:
  117. Assert.Equal (7, _textView.CursorPosition.X);
  118. Assert.Equal (0, _textView.CursorPosition.Y);
  119. Assert.Equal (0, _textView.SelectionStartColumn);
  120. Assert.Equal (0, _textView.SelectionStartRow);
  121. Assert.Equal (0, _textView.SelectedLength);
  122. Assert.Equal ("", _textView.SelectedText);
  123. break;
  124. case 2:
  125. Assert.Equal (12, _textView.CursorPosition.X);
  126. Assert.Equal (0, _textView.CursorPosition.Y);
  127. Assert.Equal (0, _textView.SelectionStartColumn);
  128. Assert.Equal (0, _textView.SelectionStartRow);
  129. Assert.Equal (0, _textView.SelectedLength);
  130. Assert.Equal ("", _textView.SelectedText);
  131. break;
  132. case 3:
  133. Assert.Equal (20, _textView.CursorPosition.X);
  134. Assert.Equal (0, _textView.CursorPosition.Y);
  135. Assert.Equal (0, _textView.SelectionStartColumn);
  136. Assert.Equal (0, _textView.SelectionStartRow);
  137. Assert.Equal (0, _textView.SelectedLength);
  138. Assert.Equal ("", _textView.SelectedText);
  139. break;
  140. case 4:
  141. Assert.Equal (25, _textView.CursorPosition.X);
  142. Assert.Equal (0, _textView.CursorPosition.Y);
  143. Assert.Equal (0, _textView.SelectionStartColumn);
  144. Assert.Equal (0, _textView.SelectionStartRow);
  145. Assert.Equal (0, _textView.SelectedLength);
  146. Assert.Equal ("", _textView.SelectedText);
  147. break;
  148. case 5:
  149. Assert.Equal (32, _textView.CursorPosition.X);
  150. Assert.Equal (0, _textView.CursorPosition.Y);
  151. Assert.Equal (0, _textView.SelectionStartColumn);
  152. Assert.Equal (0, _textView.SelectionStartRow);
  153. Assert.Equal (0, _textView.SelectedLength);
  154. Assert.Equal ("", _textView.SelectedText);
  155. break;
  156. }
  157. iteration++;
  158. }
  159. }
  160. [Fact]
  161. public void WordBackward_With_No_Selection ()
  162. {
  163. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  164. var iteration = 0;
  165. while (_textView.CursorPosition.X > 0) {
  166. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  167. switch (iteration) {
  168. case 0:
  169. Assert.Equal (25, _textView.CursorPosition.X);
  170. Assert.Equal (0, _textView.CursorPosition.Y);
  171. Assert.Equal (0, _textView.SelectionStartColumn);
  172. Assert.Equal (0, _textView.SelectionStartRow);
  173. Assert.Equal (0, _textView.SelectedLength);
  174. Assert.Equal ("", _textView.SelectedText);
  175. break;
  176. case 1:
  177. Assert.Equal (20, _textView.CursorPosition.X);
  178. Assert.Equal (0, _textView.CursorPosition.Y);
  179. Assert.Equal (0, _textView.SelectionStartColumn);
  180. Assert.Equal (0, _textView.SelectionStartRow);
  181. Assert.Equal (0, _textView.SelectedLength);
  182. Assert.Equal ("", _textView.SelectedText);
  183. break;
  184. case 2:
  185. Assert.Equal (12, _textView.CursorPosition.X);
  186. Assert.Equal (0, _textView.CursorPosition.Y);
  187. Assert.Equal (0, _textView.SelectionStartColumn);
  188. Assert.Equal (0, _textView.SelectionStartRow);
  189. Assert.Equal (0, _textView.SelectedLength);
  190. Assert.Equal ("", _textView.SelectedText);
  191. break;
  192. case 3:
  193. Assert.Equal (7, _textView.CursorPosition.X);
  194. Assert.Equal (0, _textView.CursorPosition.Y);
  195. Assert.Equal (0, _textView.SelectionStartColumn);
  196. Assert.Equal (0, _textView.SelectionStartRow);
  197. Assert.Equal (0, _textView.SelectedLength);
  198. Assert.Equal ("", _textView.SelectedText);
  199. break;
  200. case 4:
  201. Assert.Equal (4, _textView.CursorPosition.X);
  202. Assert.Equal (0, _textView.CursorPosition.Y);
  203. Assert.Equal (0, _textView.SelectionStartColumn);
  204. Assert.Equal (0, _textView.SelectionStartRow);
  205. Assert.Equal (0, _textView.SelectedLength);
  206. Assert.Equal ("", _textView.SelectedText);
  207. break;
  208. case 5:
  209. Assert.Equal (0, _textView.CursorPosition.X);
  210. Assert.Equal (0, _textView.CursorPosition.Y);
  211. Assert.Equal (0, _textView.SelectionStartColumn);
  212. Assert.Equal (0, _textView.SelectionStartRow);
  213. Assert.Equal (0, _textView.SelectedLength);
  214. Assert.Equal ("", _textView.SelectedText);
  215. break;
  216. }
  217. iteration++;
  218. }
  219. }
  220. [Fact]
  221. public void WordForward_With_Selection ()
  222. {
  223. _textView.CursorPosition = new Point (0, 0);
  224. _textView.SelectionStartColumn = 0;
  225. _textView.SelectionStartRow = 0;
  226. var iteration = 0;
  227. while (_textView.CursorPosition.X < _textView.Text.Length) {
  228. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  229. switch (iteration) {
  230. case 0:
  231. Assert.Equal (4, _textView.CursorPosition.X);
  232. Assert.Equal (0, _textView.CursorPosition.Y);
  233. Assert.Equal (0, _textView.SelectionStartColumn);
  234. Assert.Equal (0, _textView.SelectionStartRow);
  235. Assert.Equal (4, _textView.SelectedLength);
  236. Assert.Equal ("TAB ", _textView.SelectedText);
  237. break;
  238. case 1:
  239. Assert.Equal (7, _textView.CursorPosition.X);
  240. Assert.Equal (0, _textView.CursorPosition.Y);
  241. Assert.Equal (0, _textView.SelectionStartColumn);
  242. Assert.Equal (0, _textView.SelectionStartRow);
  243. Assert.Equal (7, _textView.SelectedLength);
  244. Assert.Equal ("TAB to ", _textView.SelectedText);
  245. break;
  246. case 2:
  247. Assert.Equal (12, _textView.CursorPosition.X);
  248. Assert.Equal (0, _textView.CursorPosition.Y);
  249. Assert.Equal (0, _textView.SelectionStartColumn);
  250. Assert.Equal (0, _textView.SelectionStartRow);
  251. Assert.Equal (12, _textView.SelectedLength);
  252. Assert.Equal ("TAB to jump ", _textView.SelectedText);
  253. break;
  254. case 3:
  255. Assert.Equal (20, _textView.CursorPosition.X);
  256. Assert.Equal (0, _textView.CursorPosition.Y);
  257. Assert.Equal (0, _textView.SelectionStartColumn);
  258. Assert.Equal (0, _textView.SelectionStartRow);
  259. Assert.Equal (20, _textView.SelectedLength);
  260. Assert.Equal ("TAB to jump between ", _textView.SelectedText);
  261. break;
  262. case 4:
  263. Assert.Equal (25, _textView.CursorPosition.X);
  264. Assert.Equal (0, _textView.CursorPosition.Y);
  265. Assert.Equal (0, _textView.SelectionStartColumn);
  266. Assert.Equal (0, _textView.SelectionStartRow);
  267. Assert.Equal (25, _textView.SelectedLength);
  268. Assert.Equal ("TAB to jump between text ", _textView.SelectedText);
  269. break;
  270. case 5:
  271. Assert.Equal (32, _textView.CursorPosition.X);
  272. Assert.Equal (0, _textView.CursorPosition.Y);
  273. Assert.Equal (0, _textView.SelectionStartColumn);
  274. Assert.Equal (0, _textView.SelectionStartRow);
  275. Assert.Equal (32, _textView.SelectedLength);
  276. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  277. break;
  278. }
  279. iteration++;
  280. }
  281. }
  282. [Fact]
  283. public void WordBackward_With_Selection ()
  284. {
  285. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  286. _textView.SelectionStartColumn = _textView.Text.Length;
  287. _textView.SelectionStartRow = 0;
  288. var iteration = 0;
  289. while (_textView.CursorPosition.X > 0) {
  290. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  291. switch (iteration) {
  292. case 0:
  293. Assert.Equal (25, _textView.CursorPosition.X);
  294. Assert.Equal (0, _textView.CursorPosition.Y);
  295. Assert.Equal (32, _textView.SelectionStartColumn);
  296. Assert.Equal (0, _textView.SelectionStartRow);
  297. Assert.Equal (7, _textView.SelectedLength);
  298. Assert.Equal ("fields.", _textView.SelectedText);
  299. break;
  300. case 1:
  301. Assert.Equal (20, _textView.CursorPosition.X);
  302. Assert.Equal (0, _textView.CursorPosition.Y);
  303. Assert.Equal (32, _textView.SelectionStartColumn);
  304. Assert.Equal (0, _textView.SelectionStartRow);
  305. Assert.Equal (12, _textView.SelectedLength);
  306. Assert.Equal ("text fields.", _textView.SelectedText);
  307. break;
  308. case 2:
  309. Assert.Equal (12, _textView.CursorPosition.X);
  310. Assert.Equal (0, _textView.CursorPosition.Y);
  311. Assert.Equal (32, _textView.SelectionStartColumn);
  312. Assert.Equal (0, _textView.SelectionStartRow);
  313. Assert.Equal (20, _textView.SelectedLength);
  314. Assert.Equal ("between text fields.", _textView.SelectedText);
  315. break;
  316. case 3:
  317. Assert.Equal (7, _textView.CursorPosition.X);
  318. Assert.Equal (0, _textView.CursorPosition.Y);
  319. Assert.Equal (32, _textView.SelectionStartColumn);
  320. Assert.Equal (0, _textView.SelectionStartRow);
  321. Assert.Equal (25, _textView.SelectedLength);
  322. Assert.Equal ("jump between text fields.", _textView.SelectedText);
  323. break;
  324. case 4:
  325. Assert.Equal (4, _textView.CursorPosition.X);
  326. Assert.Equal (0, _textView.CursorPosition.Y);
  327. Assert.Equal (32, _textView.SelectionStartColumn);
  328. Assert.Equal (0, _textView.SelectionStartRow);
  329. Assert.Equal (28, _textView.SelectedLength);
  330. Assert.Equal ("to jump between text fields.", _textView.SelectedText);
  331. break;
  332. case 5:
  333. Assert.Equal (0, _textView.CursorPosition.X);
  334. Assert.Equal (0, _textView.CursorPosition.Y);
  335. Assert.Equal (32, _textView.SelectionStartColumn);
  336. Assert.Equal (0, _textView.SelectionStartRow);
  337. Assert.Equal (32, _textView.SelectedLength);
  338. Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
  339. break;
  340. }
  341. iteration++;
  342. }
  343. }
  344. [Fact]
  345. public void WordForward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  346. {
  347. _textView.CursorPosition = new Point (10, 0);
  348. _textView.SelectionStartColumn = 10;
  349. _textView.SelectionStartRow = 0;
  350. var iteration = 0;
  351. while (_textView.CursorPosition.X < _textView.Text.Length) {
  352. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  353. switch (iteration) {
  354. case 0:
  355. Assert.Equal (12, _textView.CursorPosition.X);
  356. Assert.Equal (0, _textView.CursorPosition.Y);
  357. Assert.Equal (10, _textView.SelectionStartColumn);
  358. Assert.Equal (0, _textView.SelectionStartRow);
  359. Assert.Equal (2, _textView.SelectedLength);
  360. Assert.Equal ("p ", _textView.SelectedText);
  361. break;
  362. case 1:
  363. Assert.Equal (20, _textView.CursorPosition.X);
  364. Assert.Equal (0, _textView.CursorPosition.Y);
  365. Assert.Equal (10, _textView.SelectionStartColumn);
  366. Assert.Equal (0, _textView.SelectionStartRow);
  367. Assert.Equal (10, _textView.SelectedLength);
  368. Assert.Equal ("p between ", _textView.SelectedText);
  369. break;
  370. case 2:
  371. Assert.Equal (25, _textView.CursorPosition.X);
  372. Assert.Equal (0, _textView.CursorPosition.Y);
  373. Assert.Equal (10, _textView.SelectionStartColumn);
  374. Assert.Equal (0, _textView.SelectionStartRow);
  375. Assert.Equal (15, _textView.SelectedLength);
  376. Assert.Equal ("p between text ", _textView.SelectedText);
  377. break;
  378. case 3:
  379. Assert.Equal (32, _textView.CursorPosition.X);
  380. Assert.Equal (0, _textView.CursorPosition.Y);
  381. Assert.Equal (10, _textView.SelectionStartColumn);
  382. Assert.Equal (0, _textView.SelectionStartRow);
  383. Assert.Equal (22, _textView.SelectedLength);
  384. Assert.Equal ("p between text fields.", _textView.SelectedText);
  385. break;
  386. }
  387. iteration++;
  388. }
  389. }
  390. [Fact]
  391. public void WordBackward_With_The_Same_Values_For_SelectedStart_And_CursorPosition_And_Not_Starting_At_Beginning_Of_The_Text ()
  392. {
  393. _textView.CursorPosition = new Point (10, 0);
  394. _textView.SelectionStartColumn = 10;
  395. _textView.SelectionStartRow = 0;
  396. var iteration = 0;
  397. while (_textView.CursorPosition.X > 0) {
  398. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  399. switch (iteration) {
  400. case 0:
  401. Assert.Equal (7, _textView.CursorPosition.X);
  402. Assert.Equal (0, _textView.CursorPosition.Y);
  403. Assert.Equal (10, _textView.SelectionStartColumn);
  404. Assert.Equal (0, _textView.SelectionStartRow);
  405. Assert.Equal (3, _textView.SelectedLength);
  406. Assert.Equal ("jum", _textView.SelectedText);
  407. break;
  408. case 1:
  409. Assert.Equal (4, _textView.CursorPosition.X);
  410. Assert.Equal (0, _textView.CursorPosition.Y);
  411. Assert.Equal (10, _textView.SelectionStartColumn);
  412. Assert.Equal (0, _textView.SelectionStartRow);
  413. Assert.Equal (6, _textView.SelectedLength);
  414. Assert.Equal ("to jum", _textView.SelectedText);
  415. break;
  416. case 2:
  417. Assert.Equal (0, _textView.CursorPosition.X);
  418. Assert.Equal (0, _textView.CursorPosition.Y);
  419. Assert.Equal (10, _textView.SelectionStartColumn);
  420. Assert.Equal (0, _textView.SelectionStartRow);
  421. Assert.Equal (10, _textView.SelectedLength);
  422. Assert.Equal ("TAB to jum", _textView.SelectedText);
  423. break;
  424. }
  425. iteration++;
  426. }
  427. }
  428. [Fact]
  429. public void WordForward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  430. {
  431. // 1 2 3 4 5
  432. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  433. _textView.Text = "TAB t o jump b etween t ext f ields .";
  434. _textView.CursorPosition = new Point (0, 0);
  435. var iteration = 0;
  436. while (_textView.CursorPosition.X < _textView.Text.Length) {
  437. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()));
  438. switch (iteration) {
  439. case 0:
  440. Assert.Equal (6, _textView.CursorPosition.X);
  441. Assert.Equal (0, _textView.CursorPosition.Y);
  442. Assert.Equal (0, _textView.SelectionStartColumn);
  443. Assert.Equal (0, _textView.SelectionStartRow);
  444. Assert.Equal (0, _textView.SelectedLength);
  445. Assert.Equal ("", _textView.SelectedText);
  446. break;
  447. case 1:
  448. Assert.Equal (9, _textView.CursorPosition.X);
  449. Assert.Equal (0, _textView.CursorPosition.Y);
  450. Assert.Equal (0, _textView.SelectionStartColumn);
  451. Assert.Equal (0, _textView.SelectionStartRow);
  452. Assert.Equal (0, _textView.SelectedLength);
  453. Assert.Equal ("", _textView.SelectedText);
  454. break;
  455. case 2:
  456. Assert.Equal (12, _textView.CursorPosition.X);
  457. Assert.Equal (0, _textView.CursorPosition.Y);
  458. Assert.Equal (0, _textView.SelectionStartColumn);
  459. Assert.Equal (0, _textView.SelectionStartRow);
  460. Assert.Equal (0, _textView.SelectedLength);
  461. Assert.Equal ("", _textView.SelectedText);
  462. break;
  463. case 3:
  464. Assert.Equal (25, _textView.CursorPosition.X);
  465. Assert.Equal (0, _textView.CursorPosition.Y);
  466. Assert.Equal (0, _textView.SelectionStartColumn);
  467. Assert.Equal (0, _textView.SelectionStartRow);
  468. Assert.Equal (0, _textView.SelectedLength);
  469. Assert.Equal ("", _textView.SelectedText);
  470. break;
  471. case 4:
  472. Assert.Equal (28, _textView.CursorPosition.X);
  473. Assert.Equal (0, _textView.CursorPosition.Y);
  474. Assert.Equal (0, _textView.SelectionStartColumn);
  475. Assert.Equal (0, _textView.SelectionStartRow);
  476. Assert.Equal (0, _textView.SelectedLength);
  477. Assert.Equal ("", _textView.SelectedText);
  478. break;
  479. case 5:
  480. Assert.Equal (38, _textView.CursorPosition.X);
  481. Assert.Equal (0, _textView.CursorPosition.Y);
  482. Assert.Equal (0, _textView.SelectionStartColumn);
  483. Assert.Equal (0, _textView.SelectionStartRow);
  484. Assert.Equal (0, _textView.SelectedLength);
  485. Assert.Equal ("", _textView.SelectedText);
  486. break;
  487. case 6:
  488. Assert.Equal (40, _textView.CursorPosition.X);
  489. Assert.Equal (0, _textView.CursorPosition.Y);
  490. Assert.Equal (0, _textView.SelectionStartColumn);
  491. Assert.Equal (0, _textView.SelectionStartRow);
  492. Assert.Equal (0, _textView.SelectedLength);
  493. Assert.Equal ("", _textView.SelectedText);
  494. break;
  495. case 7:
  496. Assert.Equal (46, _textView.CursorPosition.X);
  497. Assert.Equal (0, _textView.CursorPosition.Y);
  498. Assert.Equal (0, _textView.SelectionStartColumn);
  499. Assert.Equal (0, _textView.SelectionStartRow);
  500. Assert.Equal (0, _textView.SelectedLength);
  501. Assert.Equal ("", _textView.SelectedText);
  502. break;
  503. case 8:
  504. Assert.Equal (48, _textView.CursorPosition.X);
  505. Assert.Equal (0, _textView.CursorPosition.Y);
  506. Assert.Equal (0, _textView.SelectionStartColumn);
  507. Assert.Equal (0, _textView.SelectionStartRow);
  508. Assert.Equal (0, _textView.SelectedLength);
  509. Assert.Equal ("", _textView.SelectedText);
  510. break;
  511. case 9:
  512. Assert.Equal (55, _textView.CursorPosition.X);
  513. Assert.Equal (0, _textView.CursorPosition.Y);
  514. Assert.Equal (0, _textView.SelectionStartColumn);
  515. Assert.Equal (0, _textView.SelectionStartRow);
  516. Assert.Equal (0, _textView.SelectedLength);
  517. Assert.Equal ("", _textView.SelectedText);
  518. break;
  519. }
  520. iteration++;
  521. }
  522. }
  523. [Fact]
  524. public void WordBackward_With_No_Selection_And_With_More_Than_Only_One_Whitespace_And_With_Only_One_Letter ()
  525. {
  526. // 1 2 3 4 5
  527. // 0123456789012345678901234567890123456789012345678901234=55 (Length)
  528. _textView.Text = "TAB t o jump b etween t ext f ields .";
  529. _textView.CursorPosition = new Point (_textView.Text.Length, 0);
  530. var iteration = 0;
  531. while (_textView.CursorPosition.X > 0) {
  532. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()));
  533. switch (iteration) {
  534. case 0:
  535. Assert.Equal (54, _textView.CursorPosition.X);
  536. Assert.Equal (0, _textView.CursorPosition.Y);
  537. Assert.Equal (0, _textView.SelectionStartColumn);
  538. Assert.Equal (0, _textView.SelectionStartRow);
  539. Assert.Equal (0, _textView.SelectedLength);
  540. Assert.Equal ("", _textView.SelectedText);
  541. break;
  542. case 1:
  543. Assert.Equal (48, _textView.CursorPosition.X);
  544. Assert.Equal (0, _textView.CursorPosition.Y);
  545. Assert.Equal (0, _textView.SelectionStartColumn);
  546. Assert.Equal (0, _textView.SelectionStartRow);
  547. Assert.Equal (0, _textView.SelectedLength);
  548. Assert.Equal ("", _textView.SelectedText);
  549. break;
  550. case 2:
  551. Assert.Equal (46, _textView.CursorPosition.X);
  552. Assert.Equal (0, _textView.CursorPosition.Y);
  553. Assert.Equal (0, _textView.SelectionStartColumn);
  554. Assert.Equal (0, _textView.SelectionStartRow);
  555. Assert.Equal (0, _textView.SelectedLength);
  556. Assert.Equal ("", _textView.SelectedText);
  557. break;
  558. case 3:
  559. Assert.Equal (40, _textView.CursorPosition.X);
  560. Assert.Equal (0, _textView.CursorPosition.Y);
  561. Assert.Equal (0, _textView.SelectionStartColumn);
  562. Assert.Equal (0, _textView.SelectionStartRow);
  563. Assert.Equal (0, _textView.SelectedLength);
  564. Assert.Equal ("", _textView.SelectedText);
  565. break;
  566. case 4:
  567. Assert.Equal (38, _textView.CursorPosition.X);
  568. Assert.Equal (0, _textView.CursorPosition.Y);
  569. Assert.Equal (0, _textView.SelectionStartColumn);
  570. Assert.Equal (0, _textView.SelectionStartRow);
  571. Assert.Equal (0, _textView.SelectedLength);
  572. Assert.Equal ("", _textView.SelectedText);
  573. break;
  574. case 5:
  575. Assert.Equal (28, _textView.CursorPosition.X);
  576. Assert.Equal (0, _textView.CursorPosition.Y);
  577. Assert.Equal (0, _textView.SelectionStartColumn);
  578. Assert.Equal (0, _textView.SelectionStartRow);
  579. Assert.Equal (0, _textView.SelectedLength);
  580. Assert.Equal ("", _textView.SelectedText);
  581. break;
  582. case 6:
  583. Assert.Equal (25, _textView.CursorPosition.X);
  584. Assert.Equal (0, _textView.CursorPosition.Y);
  585. Assert.Equal (0, _textView.SelectionStartColumn);
  586. Assert.Equal (0, _textView.SelectionStartRow);
  587. Assert.Equal (0, _textView.SelectedLength);
  588. Assert.Equal ("", _textView.SelectedText);
  589. break;
  590. case 7:
  591. Assert.Equal (12, _textView.CursorPosition.X);
  592. Assert.Equal (0, _textView.CursorPosition.Y);
  593. Assert.Equal (0, _textView.SelectionStartColumn);
  594. Assert.Equal (0, _textView.SelectionStartRow);
  595. Assert.Equal (0, _textView.SelectedLength);
  596. Assert.Equal ("", _textView.SelectedText);
  597. break;
  598. case 8:
  599. Assert.Equal (9, _textView.CursorPosition.X);
  600. Assert.Equal (0, _textView.CursorPosition.Y);
  601. Assert.Equal (0, _textView.SelectionStartColumn);
  602. Assert.Equal (0, _textView.SelectionStartRow);
  603. Assert.Equal (0, _textView.SelectedLength);
  604. Assert.Equal ("", _textView.SelectedText);
  605. break;
  606. case 9:
  607. Assert.Equal (6, _textView.CursorPosition.X);
  608. Assert.Equal (0, _textView.CursorPosition.Y);
  609. Assert.Equal (0, _textView.SelectionStartColumn);
  610. Assert.Equal (0, _textView.SelectionStartRow);
  611. Assert.Equal (0, _textView.SelectedLength);
  612. Assert.Equal ("", _textView.SelectedText);
  613. break;
  614. case 10:
  615. Assert.Equal (0, _textView.CursorPosition.X);
  616. Assert.Equal (0, _textView.CursorPosition.Y);
  617. Assert.Equal (0, _textView.SelectionStartColumn);
  618. Assert.Equal (0, _textView.SelectionStartRow);
  619. Assert.Equal (0, _textView.SelectedLength);
  620. Assert.Equal ("", _textView.SelectedText);
  621. break;
  622. }
  623. iteration++;
  624. }
  625. }
  626. [Fact]
  627. public void WordBackward_Multiline_With_Selection ()
  628. {
  629. // 4 3 2 1
  630. // 87654321098765432109876 54321098765432109876543210-Length
  631. // 1 2 1 2
  632. // 01234567890123456789012 0123456789012345678901234
  633. _textView.Text = "This is the first line.\nThis is the second line.";
  634. _textView.MoveEnd ();
  635. _textView.SelectionStartColumn = _textView.CurrentColumn;
  636. _textView.SelectionStartRow = _textView.CurrentRow;
  637. var iteration = 0;
  638. bool iterationsFinished = false;
  639. while (!iterationsFinished) {
  640. _textView.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  641. switch (iteration) {
  642. case 0:
  643. Assert.Equal (19, _textView.CursorPosition.X);
  644. Assert.Equal (1, _textView.CursorPosition.Y);
  645. Assert.Equal (24, _textView.SelectionStartColumn);
  646. Assert.Equal (1, _textView.SelectionStartRow);
  647. Assert.Equal (5, _textView.SelectedLength);
  648. Assert.Equal ("line.", _textView.SelectedText);
  649. break;
  650. case 1:
  651. Assert.Equal (12, _textView.CursorPosition.X);
  652. Assert.Equal (1, _textView.CursorPosition.Y);
  653. Assert.Equal (24, _textView.SelectionStartColumn);
  654. Assert.Equal (1, _textView.SelectionStartRow);
  655. Assert.Equal (12, _textView.SelectedLength);
  656. Assert.Equal ("second line.", _textView.SelectedText);
  657. break;
  658. case 2:
  659. Assert.Equal (8, _textView.CursorPosition.X);
  660. Assert.Equal (1, _textView.CursorPosition.Y);
  661. Assert.Equal (24, _textView.SelectionStartColumn);
  662. Assert.Equal (1, _textView.SelectionStartRow);
  663. Assert.Equal (16, _textView.SelectedLength);
  664. Assert.Equal ("the second line.", _textView.SelectedText);
  665. break;
  666. case 3:
  667. Assert.Equal (5, _textView.CursorPosition.X);
  668. Assert.Equal (1, _textView.CursorPosition.Y);
  669. Assert.Equal (24, _textView.SelectionStartColumn);
  670. Assert.Equal (1, _textView.SelectionStartRow);
  671. Assert.Equal (19, _textView.SelectedLength);
  672. Assert.Equal ("is the second line.", _textView.SelectedText);
  673. break;
  674. case 4:
  675. Assert.Equal (0, _textView.CursorPosition.X);
  676. Assert.Equal (1, _textView.CursorPosition.Y);
  677. Assert.Equal (24, _textView.SelectionStartColumn);
  678. Assert.Equal (1, _textView.SelectionStartRow);
  679. Assert.Equal (24, _textView.SelectedLength);
  680. Assert.Equal ("This is the second line.", _textView.SelectedText);
  681. break;
  682. case 5:
  683. Assert.Equal (23, _textView.CursorPosition.X);
  684. Assert.Equal (0, _textView.CursorPosition.Y);
  685. Assert.Equal (24, _textView.SelectionStartColumn);
  686. Assert.Equal (1, _textView.SelectionStartRow);
  687. Assert.Equal (25, _textView.SelectedLength);
  688. Assert.Equal ("\nThis is the second line.", _textView.SelectedText);
  689. break;
  690. case 6:
  691. Assert.Equal (18, _textView.CursorPosition.X);
  692. Assert.Equal (0, _textView.CursorPosition.Y);
  693. Assert.Equal (24, _textView.SelectionStartColumn);
  694. Assert.Equal (1, _textView.SelectionStartRow);
  695. Assert.Equal (30, _textView.SelectedLength);
  696. Assert.Equal ("line.\nThis is the second line.", _textView.SelectedText);
  697. break;
  698. case 7:
  699. Assert.Equal (12, _textView.CursorPosition.X);
  700. Assert.Equal (0, _textView.CursorPosition.Y);
  701. Assert.Equal (24, _textView.SelectionStartColumn);
  702. Assert.Equal (1, _textView.SelectionStartRow);
  703. Assert.Equal (36, _textView.SelectedLength);
  704. Assert.Equal ("first line.\nThis is the second line.", _textView.SelectedText);
  705. break;
  706. case 8:
  707. Assert.Equal (8, _textView.CursorPosition.X);
  708. Assert.Equal (0, _textView.CursorPosition.Y);
  709. Assert.Equal (24, _textView.SelectionStartColumn);
  710. Assert.Equal (1, _textView.SelectionStartRow);
  711. Assert.Equal (40, _textView.SelectedLength);
  712. Assert.Equal ("the first line.\nThis is the second line.", _textView.SelectedText);
  713. break;
  714. case 9:
  715. Assert.Equal (5, _textView.CursorPosition.X);
  716. Assert.Equal (0, _textView.CursorPosition.Y);
  717. Assert.Equal (24, _textView.SelectionStartColumn);
  718. Assert.Equal (1, _textView.SelectionStartRow);
  719. Assert.Equal (43, _textView.SelectedLength);
  720. Assert.Equal ("is the first line.\nThis is the second line.", _textView.SelectedText);
  721. break;
  722. case 10:
  723. Assert.Equal (0, _textView.CursorPosition.X);
  724. Assert.Equal (0, _textView.CursorPosition.Y);
  725. Assert.Equal (24, _textView.SelectionStartColumn);
  726. Assert.Equal (1, _textView.SelectionStartRow);
  727. Assert.Equal (48, _textView.SelectedLength);
  728. Assert.Equal ("This is the first line.\nThis is the second line.", _textView.SelectedText);
  729. break;
  730. default:
  731. iterationsFinished = true;
  732. break;
  733. }
  734. iteration++;
  735. }
  736. }
  737. [Fact]
  738. public void WordForward_Multiline_With_Selection ()
  739. {
  740. // 1 2 3 4
  741. // 01234567890123456789012 34567890123456789012345678-Length
  742. // 1 2 1 2
  743. // 01234567890123456789012 0123456789012345678901234
  744. _textView.Text = "This is the first line.\nThis is the second line.";
  745. _textView.SelectionStartColumn = _textView.CurrentColumn;
  746. _textView.SelectionStartRow = _textView.CurrentRow;
  747. var iteration = 0;
  748. bool iterationsFinished = false;
  749. while (!iterationsFinished) {
  750. _textView.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  751. switch (iteration) {
  752. case 0:
  753. Assert.Equal (5, _textView.CursorPosition.X);
  754. Assert.Equal (0, _textView.CursorPosition.Y);
  755. Assert.Equal (0, _textView.SelectionStartColumn);
  756. Assert.Equal (0, _textView.SelectionStartRow);
  757. Assert.Equal (5, _textView.SelectedLength);
  758. Assert.Equal ("This ", _textView.SelectedText);
  759. break;
  760. case 1:
  761. Assert.Equal (8, _textView.CursorPosition.X);
  762. Assert.Equal (0, _textView.CursorPosition.Y);
  763. Assert.Equal (0, _textView.SelectionStartColumn);
  764. Assert.Equal (0, _textView.SelectionStartRow);
  765. Assert.Equal (8, _textView.SelectedLength);
  766. Assert.Equal ("This is ", _textView.SelectedText);
  767. break;
  768. case 2:
  769. Assert.Equal (12, _textView.CursorPosition.X);
  770. Assert.Equal (0, _textView.CursorPosition.Y);
  771. Assert.Equal (0, _textView.SelectionStartColumn);
  772. Assert.Equal (0, _textView.SelectionStartRow);
  773. Assert.Equal (12, _textView.SelectedLength);
  774. Assert.Equal ("This is the ", _textView.SelectedText);
  775. break;
  776. case 3:
  777. Assert.Equal (18, _textView.CursorPosition.X);
  778. Assert.Equal (0, _textView.CursorPosition.Y);
  779. Assert.Equal (0, _textView.SelectionStartColumn);
  780. Assert.Equal (0, _textView.SelectionStartRow);
  781. Assert.Equal (18, _textView.SelectedLength);
  782. Assert.Equal ("This is the first ", _textView.SelectedText);
  783. break;
  784. case 4:
  785. Assert.Equal (23, _textView.CursorPosition.X);
  786. Assert.Equal (0, _textView.CursorPosition.Y);
  787. Assert.Equal (0, _textView.SelectionStartColumn);
  788. Assert.Equal (0, _textView.SelectionStartRow);
  789. Assert.Equal (23, _textView.SelectedLength);
  790. Assert.Equal ("This is the first line.", _textView.SelectedText);
  791. break;
  792. case 5:
  793. Assert.Equal (0, _textView.CursorPosition.X);
  794. Assert.Equal (1, _textView.CursorPosition.Y);
  795. Assert.Equal (0, _textView.SelectionStartColumn);
  796. Assert.Equal (0, _textView.SelectionStartRow);
  797. Assert.Equal (24, _textView.SelectedLength);
  798. Assert.Equal ("This is the first line.\n", _textView.SelectedText);
  799. break;
  800. case 6:
  801. Assert.Equal (5, _textView.CursorPosition.X);
  802. Assert.Equal (1, _textView.CursorPosition.Y);
  803. Assert.Equal (0, _textView.SelectionStartColumn);
  804. Assert.Equal (0, _textView.SelectionStartRow);
  805. Assert.Equal (29, _textView.SelectedLength);
  806. Assert.Equal ("This is the first line.\nThis ", _textView.SelectedText);
  807. break;
  808. case 7:
  809. Assert.Equal (8, _textView.CursorPosition.X);
  810. Assert.Equal (1, _textView.CursorPosition.Y);
  811. Assert.Equal (0, _textView.SelectionStartColumn);
  812. Assert.Equal (0, _textView.SelectionStartRow);
  813. Assert.Equal (32, _textView.SelectedLength);
  814. Assert.Equal ("This is the first line.\nThis is ", _textView.SelectedText);
  815. break;
  816. case 8:
  817. Assert.Equal (12, _textView.CursorPosition.X);
  818. Assert.Equal (1, _textView.CursorPosition.Y);
  819. Assert.Equal (0, _textView.SelectionStartColumn);
  820. Assert.Equal (0, _textView.SelectionStartRow);
  821. Assert.Equal (36, _textView.SelectedLength);
  822. Assert.Equal ("This is the first line.\nThis is the ", _textView.SelectedText);
  823. break;
  824. case 9:
  825. Assert.Equal (19, _textView.CursorPosition.X);
  826. Assert.Equal (1, _textView.CursorPosition.Y);
  827. Assert.Equal (0, _textView.SelectionStartColumn);
  828. Assert.Equal (0, _textView.SelectionStartRow);
  829. Assert.Equal (43, _textView.SelectedLength);
  830. Assert.Equal ("This is the first line.\nThis is the second ", _textView.SelectedText);
  831. break;
  832. case 10:
  833. Assert.Equal (24, _textView.CursorPosition.X);
  834. Assert.Equal (1, _textView.CursorPosition.Y);
  835. Assert.Equal (0, _textView.SelectionStartColumn);
  836. Assert.Equal (0, _textView.SelectionStartRow);
  837. Assert.Equal (48, _textView.SelectedLength);
  838. Assert.Equal ("This is the first line.\nThis is the second line.", _textView.SelectedText);
  839. break;
  840. default:
  841. iterationsFinished = true;
  842. break;
  843. }
  844. iteration++;
  845. }
  846. }
  847. [Fact]
  848. public void Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ()
  849. {
  850. _textView.Text = "This is the first line.\nThis is the second line.";
  851. var iteration = 0;
  852. bool iterationsFinished = false;
  853. while (!iterationsFinished) {
  854. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  855. switch (iteration) {
  856. case 0:
  857. Assert.Equal (0, _textView.CursorPosition.X);
  858. Assert.Equal (0, _textView.CursorPosition.Y);
  859. Assert.Equal ($"{System.Environment.NewLine}This is the second line.", _textView.Text);
  860. break;
  861. case 1:
  862. Assert.Equal (0, _textView.CursorPosition.X);
  863. Assert.Equal (0, _textView.CursorPosition.Y);
  864. Assert.Equal ("This is the second line.", _textView.Text);
  865. break;
  866. case 2:
  867. Assert.Equal (0, _textView.CursorPosition.X);
  868. Assert.Equal (0, _textView.CursorPosition.Y);
  869. Assert.Equal ("", _textView.Text);
  870. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  871. Assert.Equal ("This is the second line.", _textView.Text);
  872. break;
  873. default:
  874. iterationsFinished = true;
  875. break;
  876. }
  877. iteration++;
  878. }
  879. }
  880. [Fact]
  881. public void Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ()
  882. {
  883. _textView.Text = "This is the first line.\nThis is the second line.";
  884. _textView.MoveEnd ();
  885. var iteration = 0;
  886. bool iterationsFinished = false;
  887. while (!iterationsFinished) {
  888. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));
  889. switch (iteration) {
  890. case 0:
  891. Assert.Equal (0, _textView.CursorPosition.X);
  892. Assert.Equal (1, _textView.CursorPosition.Y);
  893. Assert.Equal ($"This is the first line.{System.Environment.NewLine}", _textView.Text);
  894. break;
  895. case 1:
  896. Assert.Equal (23, _textView.CursorPosition.X);
  897. Assert.Equal (0, _textView.CursorPosition.Y);
  898. Assert.Equal ("This is the first line.", _textView.Text);
  899. break;
  900. case 2:
  901. Assert.Equal (0, _textView.CursorPosition.X);
  902. Assert.Equal (0, _textView.CursorPosition.Y);
  903. Assert.Equal ("", _textView.Text);
  904. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  905. Assert.Equal ("This is the first line.", _textView.Text);
  906. break;
  907. default:
  908. iterationsFinished = true;
  909. break;
  910. }
  911. iteration++;
  912. }
  913. }
  914. [Fact]
  915. public void Kill_Delete_WordForward ()
  916. {
  917. _textView.Text = "This is the first line.";
  918. var iteration = 0;
  919. bool iterationsFinished = false;
  920. while (!iterationsFinished) {
  921. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  922. switch (iteration) {
  923. case 0:
  924. Assert.Equal (0, _textView.CursorPosition.X);
  925. Assert.Equal (0, _textView.CursorPosition.Y);
  926. Assert.Equal ("is the first line.", _textView.Text);
  927. break;
  928. case 1:
  929. Assert.Equal (0, _textView.CursorPosition.X);
  930. Assert.Equal (0, _textView.CursorPosition.Y);
  931. Assert.Equal ("the first line.", _textView.Text);
  932. break;
  933. case 2:
  934. Assert.Equal (0, _textView.CursorPosition.X);
  935. Assert.Equal (0, _textView.CursorPosition.Y);
  936. Assert.Equal ("first line.", _textView.Text);
  937. break;
  938. case 3:
  939. Assert.Equal (0, _textView.CursorPosition.X);
  940. Assert.Equal (0, _textView.CursorPosition.Y);
  941. Assert.Equal ("line.", _textView.Text);
  942. break;
  943. case 4:
  944. Assert.Equal (0, _textView.CursorPosition.X);
  945. Assert.Equal (0, _textView.CursorPosition.Y);
  946. Assert.Equal ("", _textView.Text);
  947. break;
  948. default:
  949. iterationsFinished = true;
  950. break;
  951. }
  952. iteration++;
  953. }
  954. }
  955. [Fact]
  956. public void Kill_Delete_WordBackward ()
  957. {
  958. _textView.Text = "This is the first line.";
  959. _textView.MoveEnd ();
  960. var iteration = 0;
  961. bool iterationsFinished = false;
  962. while (!iterationsFinished) {
  963. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  964. switch (iteration) {
  965. case 0:
  966. Assert.Equal (18, _textView.CursorPosition.X);
  967. Assert.Equal (0, _textView.CursorPosition.Y);
  968. Assert.Equal ("This is the first ", _textView.Text);
  969. break;
  970. case 1:
  971. Assert.Equal (12, _textView.CursorPosition.X);
  972. Assert.Equal (0, _textView.CursorPosition.Y);
  973. Assert.Equal ("This is the ", _textView.Text);
  974. break;
  975. case 2:
  976. Assert.Equal (8, _textView.CursorPosition.X);
  977. Assert.Equal (0, _textView.CursorPosition.Y);
  978. Assert.Equal ("This is ", _textView.Text);
  979. break;
  980. case 3:
  981. Assert.Equal (5, _textView.CursorPosition.X);
  982. Assert.Equal (0, _textView.CursorPosition.Y);
  983. Assert.Equal ("This ", _textView.Text);
  984. break;
  985. case 4:
  986. Assert.Equal (0, _textView.CursorPosition.X);
  987. Assert.Equal (0, _textView.CursorPosition.Y);
  988. Assert.Equal ("", _textView.Text);
  989. break;
  990. default:
  991. iterationsFinished = true;
  992. break;
  993. }
  994. iteration++;
  995. }
  996. }
  997. [Fact]
  998. public void Kill_Delete_WordForward_Multiline ()
  999. {
  1000. _textView.Text = "This is the first line.\nThis is the second line.";
  1001. _textView.Width = 4;
  1002. var iteration = 0;
  1003. bool iterationsFinished = false;
  1004. while (!iterationsFinished) {
  1005. _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()));
  1006. switch (iteration) {
  1007. case 0:
  1008. Assert.Equal (0, _textView.CursorPosition.X);
  1009. Assert.Equal (0, _textView.CursorPosition.Y);
  1010. Assert.Equal ("is the first line." + Environment.NewLine
  1011. + "This is the second line.", _textView.Text);
  1012. break;
  1013. case 1:
  1014. Assert.Equal (0, _textView.CursorPosition.X);
  1015. Assert.Equal (0, _textView.CursorPosition.Y);
  1016. Assert.Equal ("the first line." + Environment.NewLine
  1017. + "This is the second line.", _textView.Text);
  1018. break;
  1019. case 2:
  1020. Assert.Equal (0, _textView.CursorPosition.X);
  1021. Assert.Equal (0, _textView.CursorPosition.Y);
  1022. Assert.Equal ("first line." + Environment.NewLine
  1023. + "This is the second line.", _textView.Text);
  1024. break;
  1025. case 3:
  1026. Assert.Equal (0, _textView.CursorPosition.X);
  1027. Assert.Equal (0, _textView.CursorPosition.Y);
  1028. Assert.Equal ("line." + Environment.NewLine
  1029. + "This is the second line.", _textView.Text);
  1030. break;
  1031. case 4:
  1032. Assert.Equal (0, _textView.CursorPosition.X);
  1033. Assert.Equal (0, _textView.CursorPosition.Y);
  1034. Assert.Equal ("" + Environment.NewLine
  1035. + "This is the second line.", _textView.Text);
  1036. break;
  1037. case 5:
  1038. Assert.Equal (0, _textView.CursorPosition.X);
  1039. Assert.Equal (0, _textView.CursorPosition.Y);
  1040. Assert.Equal ("This is the second line.", _textView.Text);
  1041. break;
  1042. case 6:
  1043. Assert.Equal (0, _textView.CursorPosition.X);
  1044. Assert.Equal (0, _textView.CursorPosition.Y);
  1045. Assert.Equal ("is the second line.", _textView.Text);
  1046. break;
  1047. case 7:
  1048. Assert.Equal (0, _textView.CursorPosition.X);
  1049. Assert.Equal (0, _textView.CursorPosition.Y);
  1050. Assert.Equal ("the second line.", _textView.Text);
  1051. break;
  1052. case 8:
  1053. Assert.Equal (0, _textView.CursorPosition.X);
  1054. Assert.Equal (0, _textView.CursorPosition.Y);
  1055. Assert.Equal ("second line.", _textView.Text);
  1056. break;
  1057. case 9:
  1058. Assert.Equal (0, _textView.CursorPosition.X);
  1059. Assert.Equal (0, _textView.CursorPosition.Y);
  1060. Assert.Equal ("line.", _textView.Text);
  1061. break;
  1062. case 10:
  1063. Assert.Equal (0, _textView.CursorPosition.X);
  1064. Assert.Equal (0, _textView.CursorPosition.Y);
  1065. Assert.Equal ("", _textView.Text);
  1066. break;
  1067. default:
  1068. iterationsFinished = true;
  1069. break;
  1070. }
  1071. iteration++;
  1072. }
  1073. }
  1074. [Fact]
  1075. public void Kill_Delete_WordBackward_Multiline ()
  1076. {
  1077. _textView.Text = "This is the first line.\nThis is the second line.";
  1078. _textView.Width = 4;
  1079. _textView.MoveEnd ();
  1080. var iteration = 0;
  1081. bool iterationsFinished = false;
  1082. while (!iterationsFinished) {
  1083. _textView.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()));
  1084. switch (iteration) {
  1085. case 0:
  1086. Assert.Equal (19, _textView.CursorPosition.X);
  1087. Assert.Equal (1, _textView.CursorPosition.Y);
  1088. Assert.Equal ("This is the first line." + Environment.NewLine
  1089. + "This is the second ", _textView.Text);
  1090. break;
  1091. case 1:
  1092. Assert.Equal (12, _textView.CursorPosition.X);
  1093. Assert.Equal (1, _textView.CursorPosition.Y);
  1094. Assert.Equal ("This is the first line." + Environment.NewLine
  1095. + "This is the ", _textView.Text);
  1096. break;
  1097. case 2:
  1098. Assert.Equal (8, _textView.CursorPosition.X);
  1099. Assert.Equal (1, _textView.CursorPosition.Y);
  1100. Assert.Equal ("This is the first line." + Environment.NewLine
  1101. + "This is ", _textView.Text);
  1102. break;
  1103. case 3:
  1104. Assert.Equal (5, _textView.CursorPosition.X);
  1105. Assert.Equal (1, _textView.CursorPosition.Y);
  1106. Assert.Equal ("This is the first line." + Environment.NewLine
  1107. + "This ", _textView.Text);
  1108. break;
  1109. case 4:
  1110. Assert.Equal (0, _textView.CursorPosition.X);
  1111. Assert.Equal (1, _textView.CursorPosition.Y);
  1112. Assert.Equal ("This is the first line." + Environment.NewLine, _textView.Text);
  1113. break;
  1114. case 5:
  1115. Assert.Equal (23, _textView.CursorPosition.X);
  1116. Assert.Equal (0, _textView.CursorPosition.Y);
  1117. Assert.Equal ("This is the first line.", _textView.Text);
  1118. break;
  1119. case 6:
  1120. Assert.Equal (18, _textView.CursorPosition.X);
  1121. Assert.Equal (0, _textView.CursorPosition.Y);
  1122. Assert.Equal ("This is the first ", _textView.Text);
  1123. break;
  1124. case 7:
  1125. Assert.Equal (12, _textView.CursorPosition.X);
  1126. Assert.Equal (0, _textView.CursorPosition.Y);
  1127. Assert.Equal ("This is the ", _textView.Text);
  1128. break;
  1129. case 8:
  1130. Assert.Equal (8, _textView.CursorPosition.X);
  1131. Assert.Equal (0, _textView.CursorPosition.Y);
  1132. Assert.Equal ("This is ", _textView.Text);
  1133. break;
  1134. case 9:
  1135. Assert.Equal (5, _textView.CursorPosition.X);
  1136. Assert.Equal (0, _textView.CursorPosition.Y);
  1137. Assert.Equal ("This ", _textView.Text);
  1138. break;
  1139. case 10:
  1140. Assert.Equal (0, _textView.CursorPosition.X);
  1141. Assert.Equal (0, _textView.CursorPosition.Y);
  1142. Assert.Equal ("", _textView.Text);
  1143. break;
  1144. default:
  1145. iterationsFinished = true;
  1146. break;
  1147. }
  1148. iteration++;
  1149. }
  1150. }
  1151. [Fact]
  1152. public void Copy_Or_Cut_Null_If_No_Selection ()
  1153. {
  1154. _textView.SelectionStartColumn = 0;
  1155. _textView.SelectionStartRow = 0;
  1156. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1157. Assert.Equal ("", _textView.SelectedText);
  1158. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1159. Assert.Equal ("", _textView.SelectedText);
  1160. }
  1161. [Fact]
  1162. public void Copy_Or_Cut_Not_Null_If_Has_Selection ()
  1163. {
  1164. _textView.SelectionStartColumn = 20;
  1165. _textView.SelectionStartRow = 0;
  1166. _textView.CursorPosition = new Point (24, 0);
  1167. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1168. Assert.Equal ("text", _textView.SelectedText);
  1169. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1170. Assert.Equal ("", _textView.SelectedText);
  1171. }
  1172. [Fact]
  1173. public void Copy_Or_Cut_And_Paste_With_Selection ()
  1174. {
  1175. _textView.SelectionStartColumn = 20;
  1176. _textView.SelectionStartRow = 0;
  1177. _textView.CursorPosition = new Point (24, 0);
  1178. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1179. Assert.Equal ("text", _textView.SelectedText);
  1180. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1181. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1182. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1183. _textView.SelectionStartColumn = 20;
  1184. _textView.SelectionStartRow = 0;
  1185. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1186. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1187. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1188. }
  1189. [Fact]
  1190. public void Copy_Or_Cut_And_Paste_With_No_Selection ()
  1191. {
  1192. _textView.SelectionStartColumn = 20;
  1193. _textView.SelectionStartRow = 0;
  1194. _textView.CursorPosition = new Point (24, 0);
  1195. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1196. Assert.Equal ("text", _textView.SelectedText);
  1197. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1198. _textView.SelectionStartColumn = 0;
  1199. _textView.SelectionStartRow = 0;
  1200. Assert.True (_textView.Selecting);
  1201. _textView.Selecting = false;
  1202. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1203. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1204. _textView.SelectionStartColumn = 24;
  1205. _textView.SelectionStartRow = 0;
  1206. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1207. Assert.Equal ("", _textView.SelectedText);
  1208. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1209. _textView.SelectionStartColumn = 0;
  1210. _textView.SelectionStartRow = 0;
  1211. Assert.True (_textView.Selecting);
  1212. _textView.Selecting = false;
  1213. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1214. Assert.Equal ("TAB to jump between texttext fields.", _textView.Text);
  1215. }
  1216. [Fact]
  1217. public void Cut_Not_Allowed_If_ReadOnly_Is_True ()
  1218. {
  1219. _textView.ReadOnly = true;
  1220. _textView.SelectionStartColumn = 20;
  1221. _textView.SelectionStartRow = 0;
  1222. _textView.CursorPosition = new Point (24, 0);
  1223. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1224. Assert.Equal ("text", _textView.SelectedText);
  1225. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Selecting is set to false after Cut.
  1226. Assert.Equal ("", _textView.SelectedText);
  1227. _textView.ReadOnly = false;
  1228. Assert.False (_textView.Selecting);
  1229. _textView.Selecting = true; // Needed to set Selecting to true.
  1230. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1231. Assert.Equal ("text", _textView.SelectedText);
  1232. _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut
  1233. Assert.Equal ("", _textView.SelectedText);
  1234. }
  1235. [Fact]
  1236. public void Paste_Always_Clear_The_SelectedText ()
  1237. {
  1238. _textView.SelectionStartColumn = 20;
  1239. _textView.SelectionStartRow = 0;
  1240. _textView.CursorPosition = new Point (24, 0);
  1241. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1242. Assert.Equal ("text", _textView.SelectedText);
  1243. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1244. Assert.Equal ("", _textView.SelectedText);
  1245. }
  1246. [Fact]
  1247. public void TextChanged_Event ()
  1248. {
  1249. _textView.TextChanged += () => {
  1250. if (_textView.Text == "changing") {
  1251. Assert.Equal ("changing", _textView.Text);
  1252. _textView.Text = "changed";
  1253. }
  1254. };
  1255. _textView.Text = "changing";
  1256. Assert.Equal ("changed", _textView.Text);
  1257. }
  1258. [Fact]
  1259. public void Used_Is_True_By_Default ()
  1260. {
  1261. _textView.CursorPosition = new Point (10, 0);
  1262. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1263. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1264. Assert.Equal ("TAB to jumup between text fields.", _textView.Text);
  1265. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1266. Assert.Equal ("TAB to jumusp between text fields.", _textView.Text);
  1267. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1268. Assert.Equal ("TAB to jumusep between text fields.", _textView.Text);
  1269. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1270. Assert.Equal ("TAB to jumusedp between text fields.", _textView.Text);
  1271. }
  1272. [Fact]
  1273. public void Used_Is_False ()
  1274. {
  1275. _textView.Used = false;
  1276. _textView.CursorPosition = new Point (10, 0);
  1277. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1278. _textView.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
  1279. Assert.Equal ("TAB to jumu between text fields.", _textView.Text);
  1280. _textView.ProcessKey (new KeyEvent ((Key)0x73, new KeyModifiers ())); // s
  1281. Assert.Equal ("TAB to jumusbetween text fields.", _textView.Text);
  1282. _textView.ProcessKey (new KeyEvent ((Key)0x65, new KeyModifiers ())); // e
  1283. Assert.Equal ("TAB to jumuseetween text fields.", _textView.Text);
  1284. _textView.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
  1285. Assert.Equal ("TAB to jumusedtween text fields.", _textView.Text);
  1286. }
  1287. [Fact]
  1288. public void Copy_Without_Selection ()
  1289. {
  1290. _textView.Text = "This is the first line.\nThis is the second line.\n";
  1291. _textView.CursorPosition = new Point (0, _textView.Lines - 1);
  1292. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1293. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1294. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1295. _textView.CursorPosition = new Point (3, 1);
  1296. _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy
  1297. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1298. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1299. Assert.Equal (new Point (3, 2), _textView.CursorPosition);
  1300. _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste
  1301. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text);
  1302. Assert.Equal (new Point (3, 3), _textView.CursorPosition);
  1303. }
  1304. [Fact]
  1305. public void TabWidth_Setting_To_Zero_Changes_AllowsTab_To_False_If_True ()
  1306. {
  1307. Assert.Equal (4, _textView.TabWidth);
  1308. Assert.True (_textView.AllowsTab);
  1309. Assert.True (_textView.AllowsReturn);
  1310. Assert.True (_textView.Multiline);
  1311. _textView.TabWidth = -1;
  1312. Assert.Equal (0, _textView.TabWidth);
  1313. Assert.False (_textView.AllowsTab);
  1314. Assert.False (_textView.AllowsReturn);
  1315. Assert.False (_textView.Multiline);
  1316. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1317. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1318. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1319. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1320. }
  1321. [Fact]
  1322. public void AllowsTab_Setting_To_True_Changes_TabWidth_To_Default_If_It_Is_Zero ()
  1323. {
  1324. _textView.TabWidth = 0;
  1325. Assert.Equal (0, _textView.TabWidth);
  1326. Assert.False (_textView.AllowsTab);
  1327. Assert.False (_textView.AllowsReturn);
  1328. Assert.False (_textView.Multiline);
  1329. _textView.AllowsTab = true;
  1330. Assert.True (_textView.AllowsTab);
  1331. Assert.Equal (4, _textView.TabWidth);
  1332. Assert.True (_textView.AllowsReturn);
  1333. Assert.True (_textView.Multiline);
  1334. }
  1335. [Fact]
  1336. public void AllowsReturn_Setting_To_True_Changes_Multiline_To_True_If_It_Is_False ()
  1337. {
  1338. Assert.True (_textView.AllowsReturn);
  1339. Assert.True (_textView.Multiline);
  1340. Assert.Equal (4, _textView.TabWidth);
  1341. Assert.True (_textView.AllowsTab);
  1342. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1343. Assert.Equal (Environment.NewLine +
  1344. "TAB to jump between text fields.", _textView.Text);
  1345. _textView.AllowsReturn = false;
  1346. Assert.False (_textView.AllowsReturn);
  1347. Assert.False (_textView.Multiline);
  1348. Assert.Equal (0, _textView.TabWidth);
  1349. Assert.False (_textView.AllowsTab);
  1350. _textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1351. Assert.Equal (Environment.NewLine +
  1352. "TAB to jump between text fields.", _textView.Text);
  1353. }
  1354. [Fact]
  1355. public void Multiline_Setting_Changes_AllowsReturn_And_AllowsTab_And_Height ()
  1356. {
  1357. Assert.True (_textView.Multiline);
  1358. Assert.True (_textView.AllowsReturn);
  1359. Assert.Equal (4, _textView.TabWidth);
  1360. Assert.True (_textView.AllowsTab);
  1361. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1362. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1363. _textView.Multiline = false;
  1364. Assert.False (_textView.Multiline);
  1365. Assert.False (_textView.AllowsReturn);
  1366. Assert.Equal (0, _textView.TabWidth);
  1367. Assert.False (_textView.AllowsTab);
  1368. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1369. Assert.Equal ("Dim.Absolute(1)", _textView.Height.ToString ());
  1370. _textView.Multiline = true;
  1371. Assert.True (_textView.Multiline);
  1372. Assert.True (_textView.AllowsReturn);
  1373. Assert.Equal (4, _textView.TabWidth);
  1374. Assert.True (_textView.AllowsTab);
  1375. Assert.Equal ("Dim.Absolute(30)", _textView.Width.ToString ());
  1376. Assert.Equal ("Dim.Absolute(10)", _textView.Height.ToString ());
  1377. }
  1378. [Fact]
  1379. public void Tab_Test_Follow_By_BackTab ()
  1380. {
  1381. Application.Top.Add (_textView);
  1382. Application.Iteration += () => {
  1383. var width = _textView.Bounds.Width - 1;
  1384. Assert.Equal (30, width + 1);
  1385. Assert.Equal (10, _textView.Height);
  1386. _textView.Text = "";
  1387. var col = 0;
  1388. var leftCol = 0;
  1389. var tabWidth = _textView.TabWidth;
  1390. while (col < 100) {
  1391. col++;
  1392. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1393. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1394. leftCol = GetLeftCol (leftCol);
  1395. Assert.Equal (leftCol, _textView.LeftColumn);
  1396. }
  1397. while (col > 0) {
  1398. col--;
  1399. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1400. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1401. leftCol = GetLeftCol (leftCol);
  1402. Assert.Equal (leftCol, _textView.LeftColumn);
  1403. }
  1404. Application.Top.Remove (_textView);
  1405. Application.RequestStop ();
  1406. };
  1407. Application.Run ();
  1408. }
  1409. [Fact]
  1410. public void BackTab_Test_Follow_By_Tab ()
  1411. {
  1412. Application.Top.Add (_textView);
  1413. Application.Iteration += () => {
  1414. var width = _textView.Bounds.Width - 1;
  1415. Assert.Equal (30, width + 1);
  1416. Assert.Equal (10, _textView.Height);
  1417. _textView.Text = "";
  1418. for (int i = 0; i < 100; i++) {
  1419. _textView.Text += "\t";
  1420. }
  1421. var col = 100;
  1422. var tabWidth = _textView.TabWidth;
  1423. var leftCol = _textView.LeftColumn;
  1424. _textView.MoveEnd ();
  1425. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1426. leftCol = GetLeftCol (leftCol);
  1427. Assert.Equal (leftCol, _textView.LeftColumn);
  1428. while (col > 0) {
  1429. col--;
  1430. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1431. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1432. leftCol = GetLeftCol (leftCol);
  1433. Assert.Equal (leftCol, _textView.LeftColumn);
  1434. }
  1435. while (col < 100) {
  1436. col++;
  1437. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1438. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1439. leftCol = GetLeftCol (leftCol);
  1440. Assert.Equal (leftCol, _textView.LeftColumn);
  1441. }
  1442. Application.Top.Remove (_textView);
  1443. Application.RequestStop ();
  1444. };
  1445. Application.Run ();
  1446. }
  1447. [Fact]
  1448. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight ()
  1449. {
  1450. Application.Top.Add (_textView);
  1451. Application.Iteration += () => {
  1452. var width = _textView.Bounds.Width - 1;
  1453. Assert.Equal (30, width + 1);
  1454. Assert.Equal (10, _textView.Height);
  1455. _textView.Text = "";
  1456. var col = 0;
  1457. var leftCol = 0;
  1458. var tabWidth = _textView.TabWidth;
  1459. while (col < 100) {
  1460. col++;
  1461. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1462. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1463. leftCol = GetLeftCol (leftCol);
  1464. Assert.Equal (leftCol, _textView.LeftColumn);
  1465. }
  1466. while (col > 0) {
  1467. col--;
  1468. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1469. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1470. leftCol = GetLeftCol (leftCol);
  1471. Assert.Equal (leftCol, _textView.LeftColumn);
  1472. }
  1473. while (col < 100) {
  1474. col++;
  1475. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1476. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1477. leftCol = GetLeftCol (leftCol);
  1478. Assert.Equal (leftCol, _textView.LeftColumn);
  1479. }
  1480. Application.Top.Remove (_textView);
  1481. Application.RequestStop ();
  1482. };
  1483. Application.Run ();
  1484. }
  1485. [Fact]
  1486. public void Tab_Test_Follow_By_BackTab_With_Text ()
  1487. {
  1488. Application.Top.Add (_textView);
  1489. Application.Iteration += () => {
  1490. var width = _textView.Bounds.Width - 1;
  1491. Assert.Equal (30, width + 1);
  1492. Assert.Equal (10, _textView.Height);
  1493. var col = 0;
  1494. var leftCol = 0;
  1495. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1496. Assert.Equal (leftCol, _textView.LeftColumn);
  1497. while (col < 100) {
  1498. col++;
  1499. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1500. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1501. leftCol = GetLeftCol (leftCol);
  1502. Assert.Equal (leftCol, _textView.LeftColumn);
  1503. }
  1504. while (col > 0) {
  1505. col--;
  1506. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1507. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1508. leftCol = GetLeftCol (leftCol);
  1509. Assert.Equal (leftCol, _textView.LeftColumn);
  1510. }
  1511. Application.Top.Remove (_textView);
  1512. Application.RequestStop ();
  1513. };
  1514. Application.Run ();
  1515. }
  1516. [Fact]
  1517. public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_BackTab_With_Text ()
  1518. {
  1519. Application.Top.Add (_textView);
  1520. Application.Iteration += () => {
  1521. var width = _textView.Bounds.Width - 1;
  1522. Assert.Equal (30, width + 1);
  1523. Assert.Equal (10, _textView.Height);
  1524. var col = 0;
  1525. var leftCol = 0;
  1526. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1527. Assert.Equal (leftCol, _textView.LeftColumn);
  1528. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1529. Assert.Equal (32, _textView.Text.Length);
  1530. while (col < 100) {
  1531. col++;
  1532. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1533. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1534. leftCol = GetLeftCol (leftCol);
  1535. Assert.Equal (leftCol, _textView.LeftColumn);
  1536. }
  1537. _textView.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()));
  1538. col = 0;
  1539. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1540. leftCol = 0;
  1541. Assert.Equal (leftCol, _textView.LeftColumn);
  1542. _textView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()));
  1543. col = _textView.Text.Length;
  1544. Assert.Equal (132, _textView.Text.Length);
  1545. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1546. leftCol = GetLeftCol (leftCol);
  1547. Assert.Equal (leftCol, _textView.LeftColumn);
  1548. var txt = _textView.Text;
  1549. while (col - 1 > 0 && txt [col - 1] != '\t') {
  1550. col--;
  1551. }
  1552. _textView.CursorPosition = new Point (col, 0);
  1553. leftCol = GetLeftCol (leftCol);
  1554. while (col > 0) {
  1555. col--;
  1556. _textView.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ()));
  1557. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1558. leftCol = GetLeftCol (leftCol);
  1559. Assert.Equal (leftCol, _textView.LeftColumn);
  1560. }
  1561. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1562. Assert.Equal (32, _textView.Text.Length);
  1563. Application.Top.Remove (_textView);
  1564. Application.RequestStop ();
  1565. };
  1566. Application.Run ();
  1567. }
  1568. [Fact]
  1569. public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Text ()
  1570. {
  1571. Application.Top.Add (_textView);
  1572. Application.Iteration += () => {
  1573. var width = _textView.Bounds.Width - 1;
  1574. Assert.Equal (30, width + 1);
  1575. Assert.Equal (10, _textView.Height);
  1576. Assert.Equal ("TAB to jump between text fields.", _textView.Text);
  1577. var col = 0;
  1578. var leftCol = 0;
  1579. var tabWidth = _textView.TabWidth;
  1580. while (col < 100) {
  1581. col++;
  1582. _textView.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  1583. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1584. leftCol = GetLeftCol (leftCol);
  1585. Assert.Equal (leftCol, _textView.LeftColumn);
  1586. }
  1587. Assert.Equal (132, _textView.Text.Length);
  1588. while (col > 0) {
  1589. col--;
  1590. _textView.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
  1591. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1592. leftCol = GetLeftCol (leftCol);
  1593. Assert.Equal (leftCol, _textView.LeftColumn);
  1594. }
  1595. while (col < 100) {
  1596. col++;
  1597. _textView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()));
  1598. Assert.Equal (new Point (col, 0), _textView.CursorPosition);
  1599. leftCol = GetLeftCol (leftCol);
  1600. Assert.Equal (leftCol, _textView.LeftColumn);
  1601. }
  1602. Application.Top.Remove (_textView);
  1603. Application.RequestStop ();
  1604. };
  1605. Application.Run ();
  1606. }
  1607. private int GetLeftCol (int start)
  1608. {
  1609. var lines = _textView.Text.Split (Environment.NewLine);
  1610. if (lines == null || lines.Length == 0) {
  1611. return 0;
  1612. }
  1613. if (start == _textView.LeftColumn) {
  1614. return start;
  1615. }
  1616. if (_textView.LeftColumn == _textView.CurrentColumn) {
  1617. return _textView.CurrentColumn;
  1618. }
  1619. var cCol = _textView.CurrentColumn;
  1620. var line = lines [_textView.CurrentRow];
  1621. var lCount = cCol > line.Length - 1 ? line.Length - 1 : cCol;
  1622. var width = _textView.Frame.Width;
  1623. var tabWidth = _textView.TabWidth;
  1624. var sumLength = 0;
  1625. var col = 0;
  1626. for (int i = lCount; i >= 0; i--) {
  1627. var r = line [i];
  1628. sumLength += Rune.ColumnWidth (r);
  1629. if (r == '\t') {
  1630. sumLength += tabWidth + 1;
  1631. }
  1632. if (sumLength > width) {
  1633. if (cCol == line.Length) {
  1634. col++;
  1635. }
  1636. break;
  1637. } else if (cCol < line.Length && col > 0 && start < cCol && col == start) {
  1638. break;
  1639. }
  1640. col = i;
  1641. }
  1642. return col;
  1643. }
  1644. }
  1645. }