Wrong answer placeholder bounds for actions phpstorm/142.3716
authorliana.bakradze <liana.bakradze@jetbrains.com>
Mon, 3 Aug 2015 11:44:19 +0000 (14:44 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Mon, 3 Aug 2015 11:54:18 +0000 (14:54 +0300)
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderAction.java
python/educational/src/com/jetbrains/edu/courseFormat/TaskFile.java

index cee7038371e55c9363e181e53fd1e84201f5925a..9c19f2305bb7793fdcc97b494b8e2291ded5e6d9 100644 (file)
@@ -44,7 +44,9 @@ abstract public class CCAnswerPlaceholderAction extends DumbAwareAction {
     if (taskFile == null) {
       return null;
     }
-    AnswerPlaceholder answerPlaceholder = taskFile.getAnswerPlaceholder(editor.getDocument(), editor.getCaretModel().getLogicalPosition());
+    AnswerPlaceholder answerPlaceholder = taskFile.getAnswerPlaceholder(editor.getDocument(),
+                                                                        editor.getCaretModel().getLogicalPosition(),
+                                                                        true);
     if (answerPlaceholder == null) {
       return null;
     }
index df776a50db2503d722af34a197bdca449ab972ec..af372c809b7f775d41145b8d4d1069bf22aa069c 100644 (file)
@@ -97,19 +97,26 @@ public class TaskFile {
    */
   @Nullable
   public AnswerPlaceholder getAnswerPlaceholder(@NotNull final Document document, @NotNull final LogicalPosition pos) {
+    return getAnswerPlaceholder(document, pos, false);
+  }
+
+  @Nullable
+  public AnswerPlaceholder getAnswerPlaceholder(@NotNull final Document document, @NotNull final LogicalPosition pos,
+                                                boolean useAnswerLength) {
     int line = pos.line;
     if (line >= document.getLineCount()) {
       return null;
     }
     int column = pos.column;
     int offset = document.getLineStartOffset(line) + column;
-    for (AnswerPlaceholder tw : myAnswerPlaceholders) {
-      if (tw.getLine() <= line) {
-        int twStartOffset = tw.getRealStartOffset(document);
-        final int length = tw.getLength() > 0 ? tw.getLength() : 0;
-        int twEndOffset = twStartOffset + length;
-        if (twStartOffset <= offset && offset <= twEndOffset) {
-          return tw;
+    for (AnswerPlaceholder placeholder : myAnswerPlaceholders) {
+      if (placeholder.getLine() <= line) {
+        int realStartOffset = placeholder.getRealStartOffset(document);
+        int placeholderLength = useAnswerLength ? placeholder.getPossibleAnswerLength() : placeholder.getLength();
+        final int length = placeholderLength > 0 ? placeholderLength : 0;
+        int endOffset = realStartOffset + length;
+        if (realStartOffset <= offset && offset <= endOffset) {
+          return placeholder;
         }
       }
     }