### Eclipse Workspace Patch 1.0
#P sophie
Index: modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinkColorHud.java
===================================================================
--- modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinkColorHud.java	(revision 8582)
+++ modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinkColorHud.java	(working copy)
@@ -330,7 +330,7 @@
 				oldText.removeAttachment(interval).addAttachment(interval, newLink);
 
 			LogicR3.fire(frameView.textView().get(), null, null, event, 
-					TextView.EventIds.SET_TEXT,	newText, "Change normal link color");
+					TextView.EventIds.SET_TEXT,	newText, "Change normal link color", true);
 		}
 	}
 }
Index: modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextView.java
===================================================================
--- modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextView.java	(revision 8582)
+++ modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextView.java	(working copy)
@@ -249,7 +249,7 @@
 		/**
 		 * Set the text to the model.
 		 */
-		@EventParams({ImmHotText.class, String.class})
+		@EventParams({ImmHotText.class, String.class, Boolean.class})
 		SET_TEXT,
 		
 		/**
@@ -277,6 +277,10 @@
 		 * Index of the attribute value in the APPLY_STYLE operation.
 		 */
 		public static final int ATTR_VALUE_PARAM_INDEX = 1;
+		/**
+		 * Index for the input text of a SET_TEXT operation
+		 */
+		public static final int UNDO_SIGNIFICANCE_INDEX = 2;
 	}
 	
 	/**
Index: modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinksHud.java
===================================================================
--- modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinksHud.java	(revision 8582)
+++ modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinksHud.java	(working copy)
@@ -238,7 +238,7 @@
 				}
 				
 				LogicR3.fire(frameView.textView().get(), null, null, event, 
-						TextView.EventIds.SET_TEXT,	newText, description);
+						TextView.EventIds.SET_TEXT,	newText, description, true);
 				
 				return true;
 			}
Index: modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextFrameLogic.java
===================================================================
--- modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextFrameLogic.java	(revision 8582)
+++ modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextFrameLogic.java	(working copy)
@@ -277,7 +277,7 @@
 				textRes.getText().removeAttachment(interval).addAttachment(interval, newAtt);
 			
 			LogicR3.fire(headView.textView().get(), null, null, cause, 
-					TextView.EventIds.SET_TEXT,	newText, "Link visited");
+					TextView.EventIds.SET_TEXT,	newText, "Link visited", true);
 		}
 	}
 }
Index: modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/HotTextLogic.java
===================================================================
--- modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/HotTextLogic.java	(revision 8582)
+++ modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/HotTextLogic.java	(working copy)
@@ -56,7 +56,7 @@
 	 * Note that this will be done even if the text view is not editable.
 	 */
 	ON_SET_TEXT {
-		
+
 		long lastSignificantTime = 0;
 
 		public void defineFilter(EventFilterBuilder filter) {
@@ -70,18 +70,31 @@
 			if (bookView == null) {
 				return false;
 			}
-			
+			Boolean undoSignificance = event.getEventParam(TextView.EventIds.UNDO_SIGNIFICANCE_INDEX,
+					Boolean.class);
 			HotTextResourceH model = view.getModel();
 			final ImmHotText text = event.getEventParam(TextView.EventIds.TEXT_PARAM_INDEX,
 					ImmHotText.class);
+			boolean significant = false;
+			if(undoSignificance) {
+				long currentTime = System.currentTimeMillis();
+				if (currentTime - this.lastSignificantTime > 500) {
+					significant = true;
+				}
+				this.lastSignificantTime = currentTime;
+			} else {
+				//TODO: very dirty fix!!!!!!
+				final ImmHotText oldText = model.getText();
+				new AutoAction("Set old text", true) {
 
-			boolean significant = false;
-			long currentTime = System.currentTimeMillis();
-			if (currentTime - this.lastSignificantTime > 500) {
+					@Override
+					public void performAuto() {
+						getChanger().setRaw(HotTextResourceR4.KEY_TEXT, oldText);
+					}
+				}.register(model.getAccess());
 				significant = true;
 			}
-			this.lastSignificantTime = currentTime;
-			
+			//			System.out.println("significant: "+significant);
 			new AutoAction("Set text", significant) {
 
 				@Override
@@ -113,7 +126,7 @@
 
 			PageWorkArea pageWorkArea = docView.workArea().get();
 			String word = event
-					.getEventParam(QuickSearchPanel.EventIds.WORD_PARAM_ID, String.class);
+			.getEventParam(QuickSearchPanel.EventIds.WORD_PARAM_ID, String.class);
 			boolean isNext = event.getEventParam(QuickSearchPanel.EventIds.DIRECTION_PARAM_ID,
 					Boolean.class);
 			findText(word, pageWorkArea, isNext);
@@ -218,7 +231,7 @@
 			return false;
 		}
 	},
-	
+
 	/**
 	 * Interaction with the keyboard.
 	 * Supports the pasting of the copied text.
@@ -235,16 +248,16 @@
 
 			ClipboardManager manager = ClipboardManager.get();
 			DndTransferable transferable = manager.getContents();
-						
+
 			if (transferable != null) {				
 				boolean handled = pasteText(event, transferable);
 				return handled;
 			}
-			
+
 			return false;
 		}
 	},
-	
+
 	/**
 	 *	Handles "copy" regarding text. 
 	 */
@@ -268,12 +281,12 @@
 					return LogicR3.fire(textView, null, null, event, TextView.EventIds.COPY);
 				}
 			}
-			
+
 			return false;
 		}
-		
+
 	},
-	
+
 	/**
 	 * Handles "Cut" regarding text 
 	 */
@@ -297,13 +310,13 @@
 					return LogicR3.fire(textView, null, null, event, TextView.EventIds.CUT);
 				}
 			}
-			
+
 			return false;
 		}
-		
-		
+
+
 	},
-	
+
 	/**
 	 * Handles pasting of text.
 	 */
@@ -323,13 +336,13 @@
 				LogicR3.fire(textView, null, null, event, TextView.EventIds.PASTE);
 				return true;
 			}
-			
+
 			return false;
 		}
-		
 
+
 	};
-	
+
 	/**
 	 * The color used to higlight search results.
 	 */
@@ -347,25 +360,28 @@
 	 * 		Whether the event has been handled.
 	 */
 	private static boolean pasteText(EventR3 event, DndTransferable transferable) {
-		
+
 		ImmHotText textToInsert = getText(transferable);
 		if (textToInsert == null) {
 			return false;
 		}
-		
+
 		TextView source = event.getSource(TextView.class);
 		TextViewFlow flow = source.textFlow().get();
-		
+
 		if (flow.isEditable()) {
-			
+
 			ImmHotText text = flow.getText();
 
 			HotInterval interval = getSelectionEnds(flow);
 			assert interval != null;
 
-			ImmHotText newText = text.replace(interval, textToInsert);
+
+			ImmHotText newText = text.replace(interval, ImmHotText.empty());
+			newText = newText.replace(new HotInterval(interval.getBegin(),
+					interval.getBegin()), textToInsert);
 			boolean handled = LogicR3.fire(TextFlowLogic.createSetTextEvent(newText,
-					"Insert text", event));
+					"Insert text", event, false));
 
 			if (handled) {
 				HotPos newPos = newText.advance(interval.getBegin(), textToInsert.getLength());
@@ -373,10 +389,10 @@
 			}
 			return handled;
 		}
-		
+
 		return false;
 	}
-	
+
 	/**
 	 * Creates an {@link ImmHotText} instance from the contents of the given
 	 * transferable if possible.
@@ -388,21 +404,21 @@
 	 */
 	private static ImmHotText getText(DndTransferable transferable) {
 		assert transferable != null;
-		
+
 		if (transferable.getDndData(HotTextData.class) != null) {								
 			return transferable.getDndData(HotTextData.class).getContent();
 		}
-			
+
 		if (transferable.getDndData(RtfData.class) != null) {					
 			RtfTextImportManager rtfManager = new RtfTextImportManager();
 			return rtfManager.getResourceData(transferable);				
 		}
-	
+
 		if (transferable.getDndData(StringData.class) != null) {
 			String text = transferable.getDndData(StringData.class).getContent();
 			return ImmHotText.createPlain(text);
 		}
-		
+
 		return null;
 	}
 
Index: modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextFlowLogic.java
===================================================================
--- modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextFlowLogic.java	(revision 8582)
+++ modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextFlowLogic.java	(working copy)
@@ -230,7 +230,7 @@
 			}
 			
 			boolean handled = LogicR3.fire(
-					createSetTextEvent(newText, "Delete characters", event));
+					createSetTextEvent(newText, "Delete characters", event, true));
 			
 			if (handled) {
 				setSelection(flow, new HotInterval(interval.getBegin(), 
@@ -298,7 +298,7 @@
 		        		interval.getBegin(),interval.getEnd());
 		        ClipboardManager.get().setContents(contents, Operation.CUT);
 				boolean handled = LogicR3.fire(
-						createSetTextEvent(newText, "Delete characters", event));
+						createSetTextEvent(newText, "Delete characters", event, true));
 				if (handled) {
 					flow.markPos().set(flow.caretPos().get());
 				}
@@ -338,7 +338,7 @@
 			text = text.applyStyle(selection, style);
 			
 			return LogicR3.fire(
-					createSetTextEvent(text, "Apply style", event));
+					createSetTextEvent(text, "Apply style", event, false));
 		}
 		
 	},
@@ -382,7 +382,7 @@
 			ImmHotText text = flow.getText();
 			text = text.applyStyle(selection, style);
 
-			return LogicR3.fire(createSetTextEvent(text, "Apply paragraph style", event));
+			return LogicR3.fire(createSetTextEvent(text, "Apply paragraph style", event, false));
 		}
 	},
 	
@@ -456,12 +456,11 @@
 
 		HotInterval interval = getSelectionEnds(flow);
 		assert interval != null;
-
 		ImmHotText newText = immHotText.replace(interval, ImmHotText
 				.createPlain(text));
 
 		boolean handled = LogicR3.fire(createSetTextEvent(newText,
-				"Insert a character", event));
+				"Insert a character", event, true));
 
 		if (handled) {
 			int offset = text.length();
@@ -485,10 +484,15 @@
 	 * 			Description of the event.
 	 * @param cause
 	 * 			The cause of the event.
+	 * @param undoSignificance 
+	 *          If true - the undo considers the fastness of typing 
+	 *          (when undo all the changes applied in some time interval are undo)
+	 *          If false - the undo considers only the last change.
 	 * @return
 	 * 			The newly created event.
 	 */
-	public static EventR3 createSetTextEvent(ImmHotText text, String description, EventR3 cause) {
+	public static EventR3 createSetTextEvent(ImmHotText text, String description, EventR3 cause, 
+			boolean undoSignificance) {
 		List<Object> fields = new ArrayList<Object>(cause.getFields());
 		
 		fields.set(EventR3.ID_INDEX, TextView.EventIds.SET_TEXT);
@@ -496,7 +500,8 @@
 		
 		addEventParam(EventR3.PARAMS_INDEX + TextView.EventIds.TEXT_PARAM_INDEX, text, fields);
 		addEventParam(EventR3.PARAMS_INDEX + TextView.EventIds.DESCRIPTION_PARAM_INDEX, description, fields);
-
+		addEventParam(EventR3.PARAMS_INDEX + TextView.EventIds.UNDO_SIGNIFICANCE_INDEX, undoSignificance, fields);
+		
 		return new EventR3(fields);
 	}
 

