Difference between revisions of "Paste with Indentation"
(→Behavior 1: Multiple lines with leading tabs in pasting text) |
|||
(12 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
= Behaviors = | = Behaviors = | ||
− | Number of tabulations before the cursor (NC) | + | In general: |
− | Number of leading tabulations of the text being pasted (NP) | + | Adjust the number of leading tabs for each line in the pasting text by the result of the number of existing tabs before the editor cursor subtracting the number of leading tabs in the pasting text. |
+ | |||
+ | Except: | ||
+ | * There is a non-tabulation character before the editor cursor | ||
+ | * NC = 0 | ||
+ | * NP = 0 | ||
+ | |||
+ | Note: | ||
+ | * Number of tabulations before the cursor (NC) | ||
+ | * Number of leading tabulations of the text being pasted (NP) | ||
== Behavior 1: Multiple lines with leading tabs in pasting text == | == Behavior 1: Multiple lines with leading tabs in pasting text == | ||
Copied text: | Copied text: | ||
+ | |||
[[Image:Behavior_1_copied_text.PNG]] | [[Image:Behavior_1_copied_text.PNG]] | ||
=== Behavior 1.1 === | === Behavior 1.1 === | ||
− | |||
Pasted at: | Pasted at: | ||
+ | |||
[[Image:Behavior_1_1_pasted_at.PNG]] | [[Image:Behavior_1_1_pasted_at.PNG]] | ||
Result: | Result: | ||
+ | |||
[[Image:Behavior_1_1_result.PNG]] | [[Image:Behavior_1_1_result.PNG]] | ||
− | + | Summury: | |
− | + | * Remove tabs before the cursor. | |
+ | * The text pasted is indented by one tabulation (NC - NP) | ||
+ | === Behavior 1.2 === | ||
Pasted at: | Pasted at: | ||
+ | |||
[[Image:Behavior_1_2_pasted_at.PNG]] | [[Image:Behavior_1_2_pasted_at.PNG]] | ||
Result: | Result: | ||
+ | |||
[[Image:Behavior_1_2_result.PNG]] | [[Image:Behavior_1_2_result.PNG]] | ||
− | + | Summury: | |
+ | * Remove tabs before the cursor. | ||
+ | * The text pasted is not modified when (NC - NP) = 0 | ||
=== Behavior 1.3 === | === Behavior 1.3 === | ||
Pasted at: | Pasted at: | ||
+ | |||
[[Image:Behavior_1_3_pasted_at.PNG]] | [[Image:Behavior_1_3_pasted_at.PNG]] | ||
Result: | Result: | ||
+ | |||
[[Image:Behavior_1_3_result.PNG]] | [[Image:Behavior_1_3_result.PNG]] | ||
− | + | Summury: | |
+ | * Nothing has been done to the pasted text when NC = 0 | ||
== Behavior 2: Multiple lines with no tab in pasting text == | == Behavior 2: Multiple lines with no tab in pasting text == | ||
Copied text: | Copied text: | ||
+ | |||
+ | [[Image:Behavior_2_copied_text.PNG]] | ||
+ | |||
=== Behavior 2.1 === | === Behavior 2.1 === | ||
Pasted at: | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_2_1_pasted_at.PNG]] | ||
+ | |||
Result: | Result: | ||
− | + | ||
+ | [[Image:Behavior_2_1_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Nothing has been done to the pasted text when NP = 0 | ||
+ | |||
=== Behavior 2.2 === | === Behavior 2.2 === | ||
Pasted at: | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_2_2_pasted_at.PNG]] | ||
+ | |||
Result: | Result: | ||
− | + | ||
+ | [[Image:Behavior_2_2_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Nothing has been done to the pasted text when NP = 0 | ||
== Behavior 3: Single line with leading tabs in pasting text == | == Behavior 3: Single line with leading tabs in pasting text == | ||
Copied text: | Copied text: | ||
+ | |||
+ | [[Image:Behavior_3_copied_text.PNG]] | ||
=== Behavior 3.1 === | === Behavior 3.1 === | ||
Pasted at: | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_3_1_pasted_at.PNG]] | ||
+ | |||
Result: | Result: | ||
− | + | ||
+ | [[Image:Behavior_3_1_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Remove tabs before the cursor. | ||
+ | * The text pasted is indented by one tabulation (NC - NP) | ||
+ | |||
=== Behavior 3.2 === | === Behavior 3.2 === | ||
Pasted at: | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_3_2_pasted_at.PNG]] | ||
+ | |||
Result: | Result: | ||
− | + | ||
+ | [[Image:Behavior_3_2_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Remove tabs before the cursor. | ||
+ | * The text pasted is not modified when (NC - NP) = 0 | ||
+ | |||
=== Behavior 3.3 === | === Behavior 3.3 === | ||
Pasted at: | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_3_3_pasted_at.PNG]] | ||
+ | |||
Result: | Result: | ||
− | + | ||
+ | [[Image:Behavior_3_3_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Nothing is done to the text pasted when NC = 0 | ||
== Behavior 4 == | == Behavior 4 == | ||
Copied text: | Copied text: | ||
+ | |||
+ | [[Image:Behavior_4_copied_text.PNG]] | ||
+ | |||
=== Behavior 4.1 === | === Behavior 4.1 === | ||
Pasted at: | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_4_1_pasted_at.PNG]] | ||
+ | |||
Result: | Result: | ||
− | + | ||
+ | [[Image:Behavior_4_1_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Remove tabs before the cursor. | ||
+ | * The text pasted is indented by one tabulation (NC - NP) | ||
+ | * This is a good example to show this pasting behavior's advantage. Paste-as-it-is requires 4 steps to get this result. | ||
+ | |||
+ | == Behavior 5: Multiple lines with improperly formatted pasting text == | ||
+ | Copied text: | ||
+ | |||
+ | [[Image:Behavior_5_copied_text.PNG]] | ||
+ | |||
+ | === Behavior 5.1 === | ||
+ | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_5_1_pasted_at.PNG]] | ||
+ | |||
+ | Result: | ||
+ | |||
+ | [[Image:Behavior_5_1_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Remove tabs before the cursor. | ||
+ | * The text pasted is indented by one tabulation (NC - NP) | ||
+ | * The result is not perfect before the copied text is improperly formatted. One has to adjust it manually after pasting. | ||
+ | |||
+ | == Behavior 6: Paste immediately after copy == | ||
+ | Copied text: | ||
+ | |||
+ | [[Image:Behavior_5_copied_text.PNG]] | ||
+ | |||
+ | === Behavior 6.1 === | ||
+ | Pasted at: | ||
+ | |||
+ | [[Image:Behavior_5_copied_text.PNG]] | ||
+ | |||
+ | Result: | ||
+ | |||
+ | [[Image:Behavior_6_1_result.PNG]] | ||
+ | |||
+ | Summury: | ||
+ | * Paste as it is if the selection is the same as the text being pasted. |
Latest revision as of 21:58, 3 May 2012
Contents
- 1 Description
- 2 Behaviors
- 2.1 Behavior 1: Multiple lines with leading tabs in pasting text
- 2.2 Behavior 2: Multiple lines with no tab in pasting text
- 2.3 Behavior 3: Single line with leading tabs in pasting text
- 2.4 Behavior 4
- 2.5 Behavior 5: Multiple lines with improperly formatted pasting text
- 2.6 Behavior 6: Paste immediately after copy
Description
This article describes a new pasting behavior which is smarter than the regular paste-as-it-is behavior in terms of indentation. However the implementation will remain simple without using heavy Eiffel parser to reformat the text being pasted.
Behaviors
In general: Adjust the number of leading tabs for each line in the pasting text by the result of the number of existing tabs before the editor cursor subtracting the number of leading tabs in the pasting text.
Except:
- There is a non-tabulation character before the editor cursor
- NC = 0
- NP = 0
Note:
- Number of tabulations before the cursor (NC)
- Number of leading tabulations of the text being pasted (NP)
Behavior 1: Multiple lines with leading tabs in pasting text
Copied text:
Behavior 1.1
Pasted at:
Result:
Summury:
- Remove tabs before the cursor.
- The text pasted is indented by one tabulation (NC - NP)
Behavior 1.2
Pasted at:
Result:
Summury:
- Remove tabs before the cursor.
- The text pasted is not modified when (NC - NP) = 0
Behavior 1.3
Pasted at:
Result:
Summury:
- Nothing has been done to the pasted text when NC = 0
Behavior 2: Multiple lines with no tab in pasting text
Copied text:
Behavior 2.1
Pasted at:
Result:
Summury:
- Nothing has been done to the pasted text when NP = 0
Behavior 2.2
Pasted at:
Result:
Summury:
- Nothing has been done to the pasted text when NP = 0
Behavior 3: Single line with leading tabs in pasting text
Copied text:
Behavior 3.1
Pasted at:
Result:
Summury:
- Remove tabs before the cursor.
- The text pasted is indented by one tabulation (NC - NP)
Behavior 3.2
Pasted at:
Result:
Summury:
- Remove tabs before the cursor.
- The text pasted is not modified when (NC - NP) = 0
Behavior 3.3
Pasted at:
Result:
Summury:
- Nothing is done to the text pasted when NC = 0
Behavior 4
Copied text:
Behavior 4.1
Pasted at:
Result:
Summury:
- Remove tabs before the cursor.
- The text pasted is indented by one tabulation (NC - NP)
- This is a good example to show this pasting behavior's advantage. Paste-as-it-is requires 4 steps to get this result.
Behavior 5: Multiple lines with improperly formatted pasting text
Copied text:
Behavior 5.1
Pasted at:
Result:
Summury:
- Remove tabs before the cursor.
- The text pasted is indented by one tabulation (NC - NP)
- The result is not perfect before the copied text is improperly formatted. One has to adjust it manually after pasting.
Behavior 6: Paste immediately after copy
Copied text:
Behavior 6.1
Pasted at:
Result:
Summury:
- Paste as it is if the selection is the same as the text being pasted.