PY-19960 Minor Reformat
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Fri, 14 Oct 2016 14:41:24 +0000 (17:41 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 24 Oct 2016 17:09:46 +0000 (20:09 +0300)
python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbFilePanel.java

index 32ba5bc2620a31dfa9d640c326e4457748ad798e..ae00fc234bbe5765e7a43006147896e146a3ee95 100644 (file)
@@ -263,30 +263,36 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
     final List<String> currentCellSource = getCellSource(currentCellPanel);
 
     if (below) {
-      selectPrev(currentCellPanel);
+      selectNext(currentCellPanel);
     }
     else {
-      selectNext(currentCellPanel);
+      selectPrev(currentCellPanel);
     }
-    final IpnbEditablePanel prevCellPanel = getSelectedCell();
-    final IpnbCell prevCell = prevCellPanel.myCell;
-    if (prevCell instanceof IpnbEditableCell) {
-      final ArrayList<String> source = new ArrayList<>();
-      final List<String> prevCellSource = ((IpnbEditableCell)prevCell).getSource();
-      source.addAll(prevCellSource);
-      source.add("\n");
-      source.addAll(currentCellSource);
-      ((IpnbEditableCell)prevCell).setSource(source);
-      prevCellPanel.updateCellView();
+    final IpnbEditablePanel cellToMergePanel = getSelectedCell();
+    final IpnbCell cellToMerge = cellToMergePanel.myCell;
+    if (cellToMerge instanceof IpnbEditableCell) {
+      final List<String> cellToMergeSource = ((IpnbEditableCell)cellToMerge).getSource();
+      final ArrayList<String> source = below ? mergeCellsSource(cellToMergeSource, currentCellSource) : 
+                                       mergeCellsSource(currentCellSource, cellToMergeSource);
+      ((IpnbEditableCell)cellToMerge).setSource(source);
+      cellToMergePanel.updateCellView();
     }
     
-    actualizeCellData(prevCell);
+    actualizeCellData(cellToMerge);
     
     currentCellPanel.repaint();
     deleteCell(currentCellPanel);
     saveToFile();
   }
 
+  private static ArrayList<String> mergeCellsSource(List<String> currentCellSource, List<String> prevCellSource) {
+    final ArrayList<String> source = new ArrayList<>();
+    source.addAll(prevCellSource);
+    source.add("\n");
+    source.addAll(currentCellSource);
+    return source;
+  }
+
   private static void actualizeCellData(IpnbCell cell) {
     if (cell instanceof IpnbCodeCell) {
       ((IpnbCodeCell)cell).removeCellOutputs();